Implement GmailTransport.

This commit is contained in:
Markus Birth 2016-08-04 16:39:45 +02:00
parent 9c09108076
commit 868466e7d7
3 changed files with 237 additions and 19 deletions

View File

@ -6,6 +6,7 @@
"mustache/mustache": "~2.10",
"bower-asset/material-design-lite": "*",
"npm-asset/mdl-ext": "*",
"pear/mail_mime": "^1.10",
"google/apiclient": "^2.0.0@RC"
},
"require-dev": {

226
composer.lock generated
View File

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "c16fe5d634e2d6392c87fbf9c4d05519",
"content-hash": "59fa10158328c7f6a6432c72fc6fb721",
"hash": "f270ea1b6202bd524dda6e1e6f72a6d5",
"content-hash": "046c133d50b5128fa61eab7356e79289",
"packages": [
{
"name": "bower-asset/material-design-lite",
@ -406,16 +406,16 @@
},
{
"name": "monolog/monolog",
"version": "1.20.0",
"version": "1.21.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "55841909e2bcde01b5318c35f2b74f8ecc86e037"
"reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/55841909e2bcde01b5318c35f2b74f8ecc86e037",
"reference": "55841909e2bcde01b5318c35f2b74f8ecc86e037",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/f42fbdfd53e306bda545845e4dbfd3e72edb4952",
"reference": "f42fbdfd53e306bda545845e4dbfd3e72edb4952",
"shasum": ""
},
"require": {
@ -480,27 +480,27 @@
"logging",
"psr-3"
],
"time": "2016-07-02 14:02:10"
"time": "2016-07-29 03:23:52"
},
{
"name": "mustache/mustache",
"version": "v2.10.0",
"version": "v2.11.1",
"source": {
"type": "git",
"url": "https://github.com/bobthecow/mustache.php.git",
"reference": "0bb2f76e2f34a8864a32be34c4ec66274d76c05e"
"reference": "a3f6d55996dd28b58f3a909d474189a3c1aa693f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bobthecow/mustache.php/zipball/0bb2f76e2f34a8864a32be34c4ec66274d76c05e",
"reference": "0bb2f76e2f34a8864a32be34c4ec66274d76c05e",
"url": "https://api.github.com/repos/bobthecow/mustache.php/zipball/a3f6d55996dd28b58f3a909d474189a3c1aa693f",
"reference": "a3f6d55996dd28b58f3a909d474189a3c1aa693f",
"shasum": ""
},
"require": {
"php": ">=5.2.4"
},
"require-dev": {
"fabpot/php-cs-fixer": "~1.6",
"friendsofphp/php-cs-fixer": "~1.11",
"phpunit/phpunit": "~3.7|~4.0|~5.0"
},
"type": "library",
@ -526,16 +526,16 @@
"mustache",
"templating"
],
"time": "2016-02-27 19:22:46"
"time": "2016-07-31 06:18:27"
},
{
"name": "npm-asset/mdl-ext",
"version": "0.9.15",
"version": "0.9.18",
"dist": {
"type": "tar",
"url": "https://registry.npmjs.org/mdl-ext/-/mdl-ext-0.9.15.tgz",
"url": "https://registry.npmjs.org/mdl-ext/-/mdl-ext-0.9.18.tgz",
"reference": null,
"shasum": "dfab5033c85c83464aeba17d712f24d1ec85abf8"
"shasum": "dd09cb5bfe202aede8f7c827a0a15249de083bad"
},
"require-dev": {
"npm-asset/autoprefixer": "6.3.7",
@ -562,7 +562,7 @@
"npm-asset/doctrine": "1.2.2",
"npm-asset/eq.js": "1.9.0",
"npm-asset/es6-promise": "3.2.1",
"npm-asset/eslint": "3.1.1",
"npm-asset/eslint": "3.2.0",
"npm-asset/eslint-loader": "1.5.0",
"npm-asset/extract-text-webpack-plugin": "1.0.1",
"npm-asset/file-loader": "0.9.0",
@ -668,6 +668,198 @@
"webpack"
]
},
{
"name": "pear/console_getopt",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/pear/Console_Getopt.git",
"reference": "82f05cd1aa3edf34e19aa7c8ca312ce13a6a577f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Console_Getopt/zipball/82f05cd1aa3edf34e19aa7c8ca312ce13a6a577f",
"reference": "82f05cd1aa3edf34e19aa7c8ca312ce13a6a577f",
"shasum": ""
},
"type": "library",
"autoload": {
"psr-0": {
"Console": "./"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"./"
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Greg Beaver",
"email": "cellog@php.net",
"role": "Helper"
},
{
"name": "Andrei Zmievski",
"email": "andrei@php.net",
"role": "Lead"
},
{
"name": "Stig Bakken",
"email": "stig@php.net",
"role": "Developer"
}
],
"description": "More info available on: http://pear.php.net/package/Console_Getopt",
"time": "2015-07-20 20:28:12"
},
{
"name": "pear/mail_mime",
"version": "1.10.0",
"source": {
"type": "git",
"url": "https://github.com/pear/Mail_Mime.git",
"reference": "e071727cf41a4b85ecc1de210ed4fd7f4f8d1ec4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/Mail_Mime/zipball/e071727cf41a4b85ecc1de210ed4fd7f4f8d1ec4",
"reference": "e071727cf41a4b85ecc1de210ed4fd7f4f8d1ec4",
"shasum": ""
},
"require": {
"pear/pear-core-minimal": "*"
},
"type": "library",
"autoload": {
"psr-0": {
"Mail": "./"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"./"
],
"license": [
"BSD Style"
],
"authors": [
{
"name": "Cipriano Groenendal",
"email": "cipri@php.net",
"role": "Lead"
},
{
"name": "Aleksander Machniak",
"email": "alec@php.net",
"role": "Lead"
}
],
"description": "Mail_Mime provides classes to create MIME messages",
"homepage": "http://pear.php.net/package/Mail_Mime",
"time": "2015-09-13 12:42:41"
},
{
"name": "pear/pear-core-minimal",
"version": "v1.10.1",
"source": {
"type": "git",
"url": "https://github.com/pear/pear-core-minimal.git",
"reference": "cae0f1ce0cb5bddb611b0a652d322905a65a5896"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/pear-core-minimal/zipball/cae0f1ce0cb5bddb611b0a652d322905a65a5896",
"reference": "cae0f1ce0cb5bddb611b0a652d322905a65a5896",
"shasum": ""
},
"require": {
"pear/console_getopt": "~1.3",
"pear/pear_exception": "~1.0"
},
"replace": {
"rsky/pear-core-min": "self.version"
},
"type": "library",
"autoload": {
"psr-0": {
"": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"src/"
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Christian Weiske",
"email": "cweiske@php.net",
"role": "Lead"
}
],
"description": "Minimal set of PEAR core files to be used as composer dependency",
"time": "2015-10-17 11:41:19"
},
{
"name": "pear/pear_exception",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/pear/PEAR_Exception.git",
"reference": "8c18719fdae000b690e3912be401c76e406dd13b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pear/PEAR_Exception/zipball/8c18719fdae000b690e3912be401c76e406dd13b",
"reference": "8c18719fdae000b690e3912be401c76e406dd13b",
"shasum": ""
},
"require": {
"php": ">=4.4.0"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"type": "class",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-0": {
"PEAR": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
"."
],
"license": [
"BSD-2-Clause"
],
"authors": [
{
"name": "Helgi Thormar",
"email": "dufuz@php.net"
},
{
"name": "Greg Beaver",
"email": "cellog@php.net"
}
],
"description": "The PEAR Exception base class.",
"homepage": "https://github.com/pear/PEAR_Exception",
"keywords": [
"exception"
],
"time": "2015-02-10 20:07:52"
},
{
"name": "phpseclib/phpseclib",
"version": "2.0.2",

View File

@ -35,10 +35,35 @@ class GmailTransport implements TransportInterface
$this->headers = $headers;
}
/**
* Base64 encoding with URL/filename safe characters.
* Taken from http://php.net/manual/en/function.base64-encode.php#103849
*
* @param string $data Date to encode
* @return string Encoded data
*/
private function b64url_encode($data)
{
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
public function transmit()
{
$optParams = array();
$mime = new Mail_mime();
$mime->addTo($this->recipients);
$mime->setHTMLBody($this->content);
$mime->setSubject($this->subject);
$message_body = $mime->getMessage(null, null, $this->headers);
$encoded_message = $this->b64url_encode($message_body);
$postBody = new Google_Service_Gmail_Message();
$this->gms->users_messages->send('me', $postBody, $optParams);
$postBody->setRaw($encoded_message);
$msg = $this->gms->users_messages->send('me', $postBody);
if ($msg->getId()) {
return true;
}
return false;
}
}