From e278541f7aa49300cb543bbde6a4722bb862129d Mon Sep 17 00:00:00 2001 From: Zaahid Bateson Date: Sat, 7 Jan 2017 19:15:47 -0800 Subject: [PATCH] Initial commit --- composer.json | 41 ++ composer.lock | 632 ++++++++++++++++++++++++++++ config/Common.php | 81 ++++ config/Dev.default.php | 20 + config/Prod.default.php | 17 + config/Test.default.php | 18 + config/_env.php | 6 + phpunit.php | 9 + phpunit.sh | 6 + phpunit.xml.dist | 7 + src/App/Actions/EmailListAction.php | 38 ++ src/App/Actions/EmailViewAction.php | 39 ++ src/Domain/EmailFolderGateway.php | 89 ++++ templates/layouts/default.html.php | 14 + templates/views/list.html.php | 25 ++ templates/views/view.html.php | 32 ++ tests/WebProjectTest.php | 13 + web/.htaccess | 20 + web/css/default.css | 27 ++ web/index.php | 17 + 20 files changed, 1151 insertions(+) create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 config/Common.php create mode 100644 config/Dev.default.php create mode 100644 config/Prod.default.php create mode 100644 config/Test.default.php create mode 100644 config/_env.php create mode 100644 phpunit.php create mode 100755 phpunit.sh create mode 100644 phpunit.xml.dist create mode 100644 src/App/Actions/EmailListAction.php create mode 100644 src/App/Actions/EmailViewAction.php create mode 100644 src/Domain/EmailFolderGateway.php create mode 100644 templates/layouts/default.html.php create mode 100644 templates/views/list.html.php create mode 100644 templates/views/view.html.php create mode 100644 tests/WebProjectTest.php create mode 100644 web/.htaccess create mode 100644 web/css/default.css create mode 100644 web/index.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f51f362 --- /dev/null +++ b/composer.json @@ -0,0 +1,41 @@ +{ + "name": "zbateson/mailbox-folder", + "description": "Lists and displays email messages stored on a local folder", + "keywords": ["email", "inbox", "folder", "mailbox"], + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Zaahid Bateson", + "email": "zbateson@users.noreply.github.com" + } + ], + "require": { + "aura/web-kernel": "~2.1.0", + "monolog/monolog": "~1.0", + "aura/view": "~2.1.0", + "aura/html": "~2.4.0", + "zbateson/mail-mime-parser": "~0.3.0" + }, + "autoload": { + "psr-4": { + "ZBateson\\MailboxFolder\\": "src/", + "Aura\\Web_Project\\_Config\\": "config/" + } + }, + "extra": { + "aura": { + "type": "project", + "config": { + "common": "Aura\\Web_Project\\_Config\\Common", + "dev": "Aura\\Web_Project\\_Config\\Dev", + "test": "Aura\\Web_Project\\_Config\\Test", + "prod": "Aura\\Web_Project\\_Config\\Prod" + } + } + }, + "autoload-dev": { + "psr-4": { + "Aura\\Web_Project\\": "tests/" + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..fc3add6 --- /dev/null +++ b/composer.lock @@ -0,0 +1,632 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "hash": "7e5bc18c4dcba8bd6d87fe15ef8bc8dd", + "content-hash": "f345bda346e7dbe9b4c15819cd00231c", + "packages": [ + { + "name": "aura/di", + "version": "2.2.4", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Di.git", + "reference": "81d5d9c602ca292a16e32001dcbd2adab5350e28" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Di/zipball/81d5d9c602ca292a16e32001dcbd2adab5350e28", + "reference": "81d5d9c602ca292a16e32001dcbd2adab5350e28", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "library" + } + }, + "autoload": { + "psr-4": { + "Aura\\Di\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Di Contributors", + "homepage": "https://github.com/auraphp/Aura.Di/contributors" + } + ], + "description": "Provides a dependency injection container system with native support for constructor- and setter-based injection, lazy-loading of services, and inheritable configuration of setters and constructor params.", + "homepage": "https://github.com/auraphp/Aura.Di", + "keywords": [ + "container", + "dependency injection", + "dependency injection container", + "di", + "di container" + ], + "time": "2016-01-21 09:34:53" + }, + { + "name": "aura/dispatcher", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Dispatcher.git", + "reference": "d84a58d00788220077b7281f293f748470eabec5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Dispatcher/zipball/d84a58d00788220077b7281f293f748470eabec5", + "reference": "d84a58d00788220077b7281f293f748470eabec5", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "library" + } + }, + "autoload": { + "psr-4": { + "Aura\\Dispatcher\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Dispatcher Contributors", + "homepage": "https://github.com/auraphp/Aura.Dispatcher/contributors" + } + ], + "description": "Creates objects from a factory and invokes methods using named parameters; also provides a trait for invoking closures and object methods with named parameters.", + "homepage": "https://github.com/auraphp/Aura.Dispatcher", + "keywords": [ + "controller", + "dispatcher", + "factory" + ], + "time": "2016-10-03 19:45:52" + }, + { + "name": "aura/html", + "version": "2.4.1", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Html.git", + "reference": "7f575f35765af41091b85b23a92b168ae0c5765f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Html/zipball/7f575f35765af41091b85b23a92b168ae0c5765f", + "reference": "7f575f35765af41091b85b23a92b168ae0c5765f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "aura/di": "~2.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "library", + "config": { + "common": "Aura\\Html\\_Config\\Common" + } + }, + "branch-alias": { + "dev-develop-2": "2.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Aura\\Html\\": "src/", + "Aura\\Html\\_Config\\": "config/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Html Contributors", + "homepage": "https://github.com/auraphp/Aura.Html/contributors" + } + ], + "description": "Provides HTML escapers and helpers, including form input helpers.", + "homepage": "https://github.com/auraphp/Aura.Html", + "keywords": [ + "Escape", + "escaper", + "escapers", + "escaping", + "form", + "helper", + "helpers", + "html", + "input" + ], + "time": "2015-03-27 17:31:31" + }, + { + "name": "aura/project-kernel", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Project_Kernel.git", + "reference": "644475dbb4859c24aeeb309fd76a9c3e644ba9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Project_Kernel/zipball/644475dbb4859c24aeeb309fd76a9c3e644ba9be", + "reference": "644475dbb4859c24aeeb309fd76a9c3e644ba9be", + "shasum": "" + }, + "require": { + "aura/di": "~2.0", + "php": ">=5.3.0", + "psr/log": "~1.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "kernel", + "config": { + "common": "Aura\\Project_Kernel\\_Config\\Common" + } + }, + "branch-alias": { + "dev-develop-2": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Aura\\Project_Kernel\\": "src/", + "Aura\\Project_Kernel\\_Config\\": "config/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Project_Kernel Contributors", + "homepage": "https://github.com/auraphp/Aura.Project_Kernel/contributors" + } + ], + "description": "The shared kernel files for an Aura project.", + "homepage": "https://github.com/auraphp/Aura.Project_Kernel", + "keywords": [ + "kernel", + "project" + ], + "time": "2015-03-27 22:29:48" + }, + { + "name": "aura/router", + "version": "2.3.1", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Router.git", + "reference": "d8cb21b7fa8d2b2ae874093d5440688b3356f9c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Router/zipball/d8cb21b7fa8d2b2ae874093d5440688b3356f9c4", + "reference": "d8cb21b7fa8d2b2ae874093d5440688b3356f9c4", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "aura/di": "~2.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "library", + "config": { + "common": "Aura\\Router\\_Config\\Common" + } + } + }, + "autoload": { + "psr-4": { + "Aura\\Router\\": "src/", + "Aura\\Router\\_Config\\": "config/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Router Contributors", + "homepage": "https://github.com/auraphp/Aura.Router/contributors" + } + ], + "description": "A web router implementation; given a URI path and a copy of $_SERVER, it will extract path-info parameter values for a specific route.", + "homepage": "https://github.com/auraphp/Aura.Router", + "keywords": [ + "route", + "router", + "routing" + ], + "time": "2016-10-03 20:00:15" + }, + { + "name": "aura/view", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.View.git", + "reference": "defd8821dd1fe871ab23bf70bab6efc5323a701e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.View/zipball/defd8821dd1fe871ab23bf70bab6efc5323a701e", + "reference": "defd8821dd1fe871ab23bf70bab6efc5323a701e", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "aura/di": "~2.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "library", + "config": { + "common": "Aura\\View\\_Config\\Common" + } + }, + "branch-alias": { + "dev-develop-2": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Aura\\View\\": "src/", + "Aura\\View\\_Config\\": "config/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.View Contributors", + "homepage": "https://github.com/auraphp/Aura.View/contributors" + } + ], + "description": "Provides an implementation of the TemplateView and TwoStepView patterns, with support for helpers and for closures as templates, using PHP itself as the templating language.", + "homepage": "https://github.com/auraphp/Aura.View", + "keywords": [ + "Escape", + "escaper", + "escaping", + "template", + "template view", + "two step view", + "two-step view", + "twostep view", + "view" + ], + "time": "2015-03-27 18:49:40" + }, + { + "name": "aura/web", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Web.git", + "reference": "cdf90465761103c0843338aa675296100c5274d9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Web/zipball/cdf90465761103c0843338aa675296100c5274d9", + "reference": "cdf90465761103c0843338aa675296100c5274d9", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "aura/di": "~2.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "library", + "config": { + "common": "Aura\\Web\\_Config\\Common" + } + } + }, + "autoload": { + "psr-4": { + "Aura\\Web\\": "src/", + "Aura\\Web\\_Config\\": "config/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Web Contributors", + "homepage": "https://github.com/auraphp/Aura.Web/contributors" + } + ], + "description": "Provides web Request and Response objects for use by web controllers and actions. These are representations of the PHP web environment, not HTTP request and response objects proper.", + "homepage": "https://github.com/auraphp/Aura.Web", + "keywords": [ + "request", + "response" + ], + "time": "2016-10-03 21:32:34" + }, + { + "name": "aura/web-kernel", + "version": "2.1.3", + "source": { + "type": "git", + "url": "https://github.com/auraphp/Aura.Web_Kernel.git", + "reference": "42ab3bec4ccc83f575a1ea869ded964a3893aebe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/auraphp/Aura.Web_Kernel/zipball/42ab3bec4ccc83f575a1ea869ded964a3893aebe", + "reference": "42ab3bec4ccc83f575a1ea869ded964a3893aebe", + "shasum": "" + }, + "require": { + "aura/dispatcher": "~2.0", + "aura/project-kernel": "~2.0", + "aura/router": "~2.0", + "aura/web": "~2.0", + "php": ">=5.4.0" + }, + "type": "library", + "extra": { + "aura": { + "type": "kernel", + "config": { + "common": "Aura\\Web_Kernel\\_Config\\Common", + "web-kernel-test": "Aura\\Web_Kernel\\_Config\\WebKernelTest" + } + } + }, + "autoload": { + "psr-4": { + "Aura\\Web_Kernel\\": "src/", + "Aura\\Web_Kernel\\_Config\\": "config/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Aura.Web_Kernel Contributors", + "homepage": "https://github.com/auraphp/Aura.Web_Kernel/contributors" + } + ], + "description": "The kernel files for an Aura web project.", + "homepage": "https://github.com/auraphp/Aura.Web_Kernel", + "keywords": [ + "kernel", + "web" + ], + "time": "2016-10-03 21:38:39" + }, + { + "name": "monolog/monolog", + "version": "1.22.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/monolog.git", + "reference": "bad29cb8d18ab0315e6c477751418a82c850d558" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bad29cb8d18ab0315e6c477751418a82c850d558", + "reference": "bad29cb8d18ab0315e6c477751418a82c850d558", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "psr/log": "~1.0" + }, + "provide": { + "psr/log-implementation": "1.0.0" + }, + "require-dev": { + "aws/aws-sdk-php": "^2.4.9 || ^3.0", + "doctrine/couchdb": "~1.0@dev", + "graylog2/gelf-php": "~1.0", + "jakub-onderka/php-parallel-lint": "0.9", + "php-amqplib/php-amqplib": "~2.4", + "php-console/php-console": "^3.1.3", + "phpunit/phpunit": "~4.5", + "phpunit/phpunit-mock-objects": "2.3.0", + "ruflin/elastica": ">=0.90 <3.0", + "sentry/sentry": "^0.13", + "swiftmailer/swiftmailer": "~5.3" + }, + "suggest": { + "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", + "doctrine/couchdb": "Allow sending log messages to a CouchDB server", + "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-mongo": "Allow sending log messages to a MongoDB server", + "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", + "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", + "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", + "php-console/php-console": "Allow sending log messages to Google Chrome", + "rollbar/rollbar": "Allow sending log messages to Rollbar", + "ruflin/elastica": "Allow sending log messages to an Elastic Search server", + "sentry/sentry": "Allow sending log messages to a Sentry server" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Monolog\\": "src/Monolog" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Sends your logs to files, sockets, inboxes, databases and various web services", + "homepage": "http://github.com/Seldaek/monolog", + "keywords": [ + "log", + "logging", + "psr-3" + ], + "time": "2016-11-26 00:15:39" + }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10 12:19:37" + }, + { + "name": "zbateson/mail-mime-parser", + "version": "0.3.3", + "source": { + "type": "git", + "url": "https://github.com/zbateson/MailMimeParser.git", + "reference": "b2e1e512e7475a2c72c8cdeff76ce07a42b5636d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zbateson/MailMimeParser/zipball/b2e1e512e7475a2c72c8cdeff76ce07a42b5636d", + "reference": "b2e1e512e7475a2c72c8cdeff76ce07a42b5636d", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=5.4" + }, + "require-dev": { + "evert/phpdoc-md": "~0.1.1", + "phing/phing": "2.*", + "phpdocumentor/phpdocumentor": "2.*", + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "ZBateson\\MailMimeParser\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Zaahid Bateson", + "email": "zbateson@users.noreply.github.com" + } + ], + "description": "PSR-2 compliant mime mail parser", + "homepage": "https://github.com/zbateson/MailMimeParser", + "keywords": [ + "mail", + "mime", + "parser" + ], + "time": "2016-12-22 21:28:11" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/config/Common.php b/config/Common.php new file mode 100644 index 0000000..dbafc49 --- /dev/null +++ b/config/Common.php @@ -0,0 +1,81 @@ +set('aura/project-kernel:logger', $di->lazyNew('Monolog\Logger')); + + $di->params['Aura\View\View']['helpers'] = $di->lazyGet('aura/html:helper'); + $di->params['Aura\View\TemplateRegistry']['paths'] = [ + dirname(__DIR__) . '/templates/views', + dirname(__DIR__) . '/templates/layouts', + ]; + $di->set('view', $di->lazyNew('Aura\View\View')); + + $di->params['ZBateson\MailboxFolder\Domain\EmailFolderGateway'] = [ + 'mailMimeParser' => $di->lazyNew('ZBateson\MailMimeParser\MailMimeParser'), + ]; + $di->params['ZBateson\MailboxFolder\App\Actions\EmailListAction'] = [ + 'request' => $di->lazyGet('aura/web-kernel:request'), + 'response' => $di->lazyGet('aura/web-kernel:response'), + 'view' => $di->lazyGet('view'), + 'emailFolderGateway' => $di->lazyNew('ZBateson\MailboxFolder\Domain\EmailFolderGateway'), + ]; + $di->params['ZBateson\MailboxFolder\App\Actions\EmailViewAction'] = [ + 'request' => $di->lazyGet('aura/web-kernel:request'), + 'response' => $di->lazyGet('aura/web-kernel:response'), + 'view' => $di->lazyGet('view'), + 'emailFolderGateway' => $di->lazyNew('ZBateson\MailboxFolder\Domain\EmailFolderGateway'), + ]; + } + + public function modify(Container $di) + { + $this->modifyLogger($di); + $this->modifyWebRouter($di); + $this->modifyWebDispatcher($di); + } + + public function modifyLogger(Container $di) + { + $project = $di->get('project'); + $mode = $project->getMode(); + $file = $project->getPath("tmp/log/{$mode}.log"); + + $logger = $di->get('aura/project-kernel:logger'); + $logger->pushHandler($di->newInstance( + 'Monolog\Handler\StreamHandler', + [ + 'stream' => $file, + ] + )); + } + + public function modifyWebRouter(Container $di) + { + $router = $di->get('aura/web-kernel:router'); + + $router->add('list', '/') + ->setValues(['action' => 'list']); + $router->add('view', '/view') + ->setValues(['action' => 'view']); + } + + public function modifyWebDispatcher($di) + { + $dispatcher = $di->get('aura/web-kernel:dispatcher'); + $dispatcher->setObject( + 'list', + $di->lazyNew('ZBateson\MailboxFolder\App\Actions\EmailListAction') + ); + $dispatcher->setObject( + 'view', + $di->lazyNew('ZBateson\MailboxFolder\App\Actions\EmailViewAction') + ); + } +} diff --git a/config/Dev.default.php b/config/Dev.default.php new file mode 100644 index 0000000..339a30a --- /dev/null +++ b/config/Dev.default.php @@ -0,0 +1,20 @@ +setter['ZBateson\MailboxFolder\Domain\EmailFolderGateway']['setPath'] = '/path/to/mailbox/folder'; + } + + public function modify(Container $di) + { + } +} diff --git a/config/Prod.default.php b/config/Prod.default.php new file mode 100644 index 0000000..9adc509 --- /dev/null +++ b/config/Prod.default.php @@ -0,0 +1,17 @@ +setter['ZBateson\MailboxFolder\Domain\EmailFolderGateway']['setPath'] = '/path/to/mailbox/folder'; + } + + public function modify(Container $di) + { + } +} diff --git a/config/Test.default.php b/config/Test.default.php new file mode 100644 index 0000000..f7c9ec7 --- /dev/null +++ b/config/Test.default.php @@ -0,0 +1,18 @@ +setter['ZBateson\MailboxFolder\Domain\EmailFolderGateway']['setPath'] = '/path/to/mailbox/folder'; + } + + public function modify(Container $di) + { + + } +} diff --git a/config/_env.php b/config/_env.php new file mode 100644 index 0000000..5c2e8d1 --- /dev/null +++ b/config/_env.php @@ -0,0 +1,6 @@ + + + + ./tests + + + diff --git a/src/App/Actions/EmailListAction.php b/src/App/Actions/EmailListAction.php new file mode 100644 index 0000000..916c9fe --- /dev/null +++ b/src/App/Actions/EmailListAction.php @@ -0,0 +1,38 @@ +request = $request; + $this->response = $response; + $this->view = $view; + $this->emailFolderGateway = $emailFolderGateway; + } + + public function __invoke() + { + $this->view->setData([ + 'emails' => $this->emailFolderGateway->fetchAll() + ]); + $this->view->setView('list.html'); + $this->view->setLayout('default.html'); + $this->response->content->set($this->view->__invoke()); + } +} diff --git a/src/App/Actions/EmailViewAction.php b/src/App/Actions/EmailViewAction.php new file mode 100644 index 0000000..3819eb5 --- /dev/null +++ b/src/App/Actions/EmailViewAction.php @@ -0,0 +1,39 @@ +request = $request; + $this->response = $response; + $this->view = $view; + $this->emailFolderGateway = $emailFolderGateway; + } + + public function __invoke() + { + $file = $this->request->query->get("name"); + $this->view->setData([ + 'email' => $this->emailFolderGateway->fetchBy($file) + ]); + $this->view->setView('view.html'); + $this->view->setLayout('default.html'); + $this->response->content->set($this->view->__invoke()); + } +} diff --git a/src/Domain/EmailFolderGateway.php b/src/Domain/EmailFolderGateway.php new file mode 100644 index 0000000..e20ffb1 --- /dev/null +++ b/src/Domain/EmailFolderGateway.php @@ -0,0 +1,89 @@ +mailMimeParser = $mailMimeParser; + } + + public function setPath($path) + { + $this->path = $path; + } + + /** + * Returns an array of email messages as ZBateson\MailMimeParser\Message + * objects. + * + * @return \ZBateson\MailMimeParser\Message[] + */ + public function fetchAll() + { + $di = new DirectoryIterator($this->path); + $emails = []; + foreach ($di as $fi) { + if (!$fi->isFile() || !$fi->isReadable()) { + continue; + } + $handle = fopen($fi->getPathname(), 'r'); + $message = $this->mailMimeParser->parse($handle); + fclose($handle); + $ctime = DateTime::createFromFormat('U', $fi->getCTime()); + $message->setRawHeader( + 'Date', + $message->getHeaderValue( + 'Date', + $ctime->format('r') + ) + ); + $emails[$fi->getFilename()] = $message; + } + uasort( + $emails, + function ($a, $b) { + return ($b->getHeader('Date')->getDateTime()->getTimestamp() - $a->getHeader('Date')->getDateTime()->getTimestamp()); + } + ); + return $emails; + } + + /** + * Returns a Message object for the email + * + * @param string $filename + * @return \ZBateson\MailMimeParser\Message + */ + public function fetchBy($filename) + { + $filepath = $this->path . DIRECTORY_SEPARATOR . $filename; + $uctime = filectime($filepath); + $handle = fopen($filepath, 'r'); + $message = $this->mailMimeParser->parse($handle); + fclose($handle); + $ctime = DateTime::createFromFormat('U', $uctime); + $message->setRawHeader( + 'Date', + $message->getHeaderValue( + 'Date', + $ctime->format('r') + ) + ); + return $message; + } +} diff --git a/templates/layouts/default.html.php b/templates/layouts/default.html.php new file mode 100644 index 0000000..54e9341 --- /dev/null +++ b/templates/layouts/default.html.php @@ -0,0 +1,14 @@ +title(' - MailboxFolder'); +?> + + + + + + title(); ?> + + + getContent(); ?> + + diff --git a/templates/views/list.html.php b/templates/views/list.html.php new file mode 100644 index 0000000..f42633e --- /dev/null +++ b/templates/views/list.html.php @@ -0,0 +1,25 @@ +title('Outgoing emails listing'); +?> +

+ Outgoing emails - listing +

+
+
+
Subject
+
Date
+
To
+
+ emails as $filename => $email) { + $subject = $email->getHeaderValue('Subject', ''); + ?> + + escape()->html($subject);?> + escape()->html($email->getHeader('Date')->getDateTime()->format('Y-m-d H:i:s'));?> + escape()->html($email->getHeaderValue('To'));?> + + +
diff --git a/templates/views/view.html.php b/templates/views/view.html.php new file mode 100644 index 0000000..a6726d1 --- /dev/null +++ b/templates/views/view.html.php @@ -0,0 +1,32 @@ +email->getHeaderValue('Subject', ''); +$this->title($subject); +?> +

+ Outgoing emails - listing > + escape()->html($subject);?> +

+ + + diff --git a/tests/WebProjectTest.php b/tests/WebProjectTest.php new file mode 100644 index 0000000..4dd43a0 --- /dev/null +++ b/tests/WebProjectTest.php @@ -0,0 +1,13 @@ +assertSame($expect, $actual); + } +} diff --git a/web/.htaccess b/web/.htaccess new file mode 100644 index 0000000..6e2f824 --- /dev/null +++ b/web/.htaccess @@ -0,0 +1,20 @@ + + # turn on rewriting + RewriteEngine On + + # turn empty requests into requests for "index.php", + # keeping the query string intact + RewriteRule ^$ index.php [QSA] + + # look for cached versions of files in ./web/cache/ + RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} -f + RewriteRule ^(.*)$ cache/$1 [L] + + # for all files not found in the file system, + # reroute to "index.php" bootstrap script, + # keeping the query string intact. + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !favicon.ico$ + RewriteRule ^(.*)$ index.php [QSA,L] + diff --git a/web/css/default.css b/web/css/default.css new file mode 100644 index 0000000..6848a23 --- /dev/null +++ b/web/css/default.css @@ -0,0 +1,27 @@ +/* + Created on : 28-Oct-2015, 4:28:07 PM + Author : Zaahid Bateson +*/ +body{font:14px Helvetica;margin:10px;} +.heading{padding:15px 0px;margin:0px;font-size:1.5em} +.heading a{color:#002145;text-decoration:none} +.heading .sub{font-size:0.6em} +.inbox-list a:link,.inbox-list a:visited{color:inherit;text-decoration:none} +.inbox-list a:hover,.inbox-list a:focus{background-color:#002145;color:#fff} +.inbox-list a:active{background-color:#f80} +.inbox-list{background:#fff;display:table;width:100%} +.inbox-list .row{min-height:20px;background:#98B2C3;margin:2px 0px;display:table-row} +.inbox-list .column{padding:5px;display:table-cell} +.inbox-list .header{background-color:#2F5D7C;font-weight:bold;color:#fff} +.inbox-list .subject{width:55%} +.inbox-list .date{width:15%} +.inbox-list .to{width:30%} +.inbox-list .end-row{clear:left} + +.email-headers{background:#98B2C3;margin:0px;padding:15px;border-bottom:3px #000 groove;line-height:18px} +.email-headers dl{margin:0px;padding:0px} +.email-headers dt{width:180px;clear:both;float:left;text-align:right;color:#444} +.email-headers dd{margin-left:190px} +.email-headers .back{text-align:right} +.email-headers .back a{color:#fff} +.email-body{padding:15px} \ No newline at end of file diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..e8fc280 --- /dev/null +++ b/web/index.php @@ -0,0 +1,17 @@ +newKernel( + $path, + 'Aura\Web_Kernel\WebKernel' +); +$kernel();