-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from conjoon/dev
Dev
- Loading branch information
Showing
13 changed files
with
261 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/Illuminate/Auth/LocalMailAccount/LocalAccountProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/** | ||
* conjoon | ||
* php-lib-conjoon | ||
* Copyright (C) 2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
* files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, | ||
* publish, distribute, sublicense, and/or sell copies of the Software, | ||
* and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | ||
* USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Conjoon\Illuminate\Auth\LocalMailAccount; | ||
|
||
use Conjoon\Illuminate\Auth\Imap\DefaultImapUserProvider; | ||
use Conjoon\Illuminate\Auth\ImapUser; | ||
use Conjoon\Mail\Client\Data\MailAccount; | ||
use Illuminate\Http\Request; | ||
|
||
/** | ||
* Auth provider that expects required mailserver configurations to be available | ||
* with the payload ("x-cnmail-data"-header). | ||
*/ | ||
class LocalAccountProvider extends DefaultImapUserProvider | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $payload; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $mailAccountId; | ||
|
||
|
||
public function __construct(Request $request) | ||
{ | ||
$this->payload = $request->header("x-cnmail-data"); | ||
$this->mailAccountId = $request->route('mailAccountId'); | ||
} | ||
|
||
|
||
public function getUser(string $username, string $password): ?ImapUser | ||
{ | ||
$config = $this->decodePayload($this->payload); | ||
$mailAccount = $this->createMailAccount($username, $password, $config); | ||
|
||
return new ImapUser($username, $password, $mailAccount); | ||
} | ||
|
||
private function createMailAccount(string $username, string $password, array $config): MailAccount | ||
{ | ||
$merged = array_merge($config, [ | ||
"id" => $this->mailAccountId, | ||
"name" => $this->mailAccountId, | ||
"inbox_user" => $username, | ||
"inbox_password" => $password | ||
]); | ||
return new MailAccount($merged); | ||
} | ||
|
||
private function decodePayload(string $payload): array | ||
{ | ||
return json_decode(base64_decode($payload), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
/** | ||
* conjoon | ||
* php-lib-conjoon | ||
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon | ||
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
* obtaining a copy of this software and associated documentation | ||
|
@@ -56,14 +56,14 @@ | |
* "outbox_user" => "outboxuser", | ||
* "outbox_password" => "outboxpassword', | ||
* 'outbox_secure' => "tls", | ||
* 'root' => "INBOX" | ||
* 'subscriptions' => ["INBOX"] | ||
* ]); | ||
* | ||
* $account->getOutboxSecure(); // true | ||
* $account->getInboxPort(); // 993 | ||
* $account->getReplyTo(); // ['name' => 'John Smith', 'address' => '[email protected]'], | ||
* | ||
* The property "root" allows for specifying a root mailbox and defaults to "INBOX". | ||
* The property "subscriptions" allows for specifying mailbox the account is subscribed to. | ||
* | ||
* @package Conjoon\Mail\Client\Data | ||
* | ||
|
@@ -82,7 +82,7 @@ | |
* @method string getOutboxAddress() | ||
* @method int getOutboxPort() | ||
* @method string getOutboxSecure() | ||
* @method array getRoot() | ||
* @method array getSubscriptions() | ||
* | ||
* @noinspection SpellCheckingInspection | ||
*/ | ||
|
@@ -166,7 +166,7 @@ class MailAccount implements Jsonable, Arrayable | |
/** | ||
* @var array | ||
*/ | ||
protected array $root = ["INBOX"]; | ||
protected array $subscriptions = ["INBOX"]; | ||
|
||
/** | ||
* MailAccount constructor. | ||
|
@@ -240,7 +240,7 @@ public function toArray(): array | |
"outbox_user" => $this->getOutboxUser(), | ||
"outbox_password" => $this->getOutboxPassword(), | ||
"outbox_secure" => $this->getOutboxSecure(), | ||
"root" => $this->getRoot() | ||
"subscriptions" => $this->getSubscriptions() | ||
]; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.