Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conjoon#23 #13

Merged
merged 5 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Auth/Imap/DefaultImapUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,6 +30,8 @@
namespace Conjoon\Illuminate\Auth\Imap;

use Conjoon\Illuminate\Auth\Imap\Util as ImapUtil;
use Conjoon\Illuminate\Auth\ImapUser;
use Conjoon\Illuminate\Auth\ImapUserProvider;
use Illuminate\Contracts\Auth\Authenticatable;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +27,7 @@

declare(strict_types=1);

namespace Conjoon\Illuminate\Auth\Imap;
namespace Conjoon\Illuminate\Auth;

use Conjoon\Mail\Client\Data\MailAccount;
use Illuminate\Contracts\Auth\Authenticatable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,8 +27,9 @@

declare(strict_types=1);

namespace Conjoon\Illuminate\Auth\Imap;
namespace Conjoon\Illuminate\Auth;

use Conjoon\Illuminate\Auth\Imap\Conjoon;
use Illuminate\Contracts\Auth\UserProvider;

/**
Expand All @@ -45,7 +46,7 @@ interface ImapUserProvider extends UserProvider
* @param string $username
* @param string $password
*
* @return Conjoon\Illuminate\Auth\Imap\ImapUser|null
* @return ImapUser|null
*/
public function getUser(string $username, string $password): ?ImapUser;
}
84 changes: 84 additions & 0 deletions src/Illuminate/Auth/LocalMailAccount/LocalAccountProvider.php
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);
}
}
12 changes: 6 additions & 6 deletions src/Mail/Client/Data/MailAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand All @@ -82,7 +82,7 @@
* @method string getOutboxAddress()
* @method int getOutboxPort()
* @method string getOutboxSecure()
* @method array getRoot()
* @method array getSubscriptions()
*
* @noinspection SpellCheckingInspection
*/
Expand Down Expand Up @@ -166,7 +166,7 @@ class MailAccount implements Jsonable, Arrayable
/**
* @var array
*/
protected array $root = ["INBOX"];
protected array $subscriptions = ["INBOX"];

/**
* MailAccount constructor.
Expand Down Expand Up @@ -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()
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/Mail/Client/Service/DefaultMailFolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,10 +92,10 @@ public function getMailClient(): MailClient
/**
* @inheritdoc
*/
public function getMailFolderChildList(MailAccount $mailAccount): MailFolderChildList
public function getMailFolderChildList(MailAccount $mailAccount, array $subscriptions = []): MailFolderChildList
{
$mailFolderList = $this->getMailClient()->getMailFolderList($mailAccount);

return $this->getMailFolderTreeBuilder()->listToTree($mailFolderList, $mailAccount->getRoot());
return $this->getMailFolderTreeBuilder()->listToTree($mailFolderList, $subscriptions);
}
}
5 changes: 3 additions & 2 deletions src/Mail/Client/Service/MailFolderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,6 +40,7 @@ interface MailFolderService
* MailAccount.
*
* @param MailAccount $mailAccount
* @param array $subscriptions
*
* @return MailFolderChildList An MailFolderChildList of the Mailbox-structure
* found on the server.
Expand All @@ -55,7 +56,7 @@ interface MailFolderService
*
* @see \Horde_Imap_Client_Socket
*/
public function getMailFolderChildList(MailAccount $mailAccount): MailFolderChildList;
public function getMailFolderChildList(MailAccount $mailAccount, array $subscriptions = []): MailFolderChildList;


/**
Expand Down
9 changes: 4 additions & 5 deletions tests/Illuminate/Auth/Imap/DefaultImapUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,14 +30,13 @@
namespace Tests\Conjoon\Illuminate\Auth\Imap;

use Conjoon\Illuminate\Auth\Imap\DefaultImapUserProvider;
use Conjoon\Illuminate\Auth\Imap\ImapUser;
use Conjoon\Illuminate\Auth\Imap\ImapUserProvider;
use Conjoon\Mail\Client\Data\MailAccount;
use Conjoon\Illuminate\Auth\ImapUser;
use Conjoon\Illuminate\Auth\ImapUserProvider;
use Tests\TestCase;

/**
* Class DefaultImapUserProviderTest
* @package Tests\Conjoon\Illuminate\Auth\Imap
* Tests DefaultImapUserProvider.
*/
class DefaultImapUserProviderTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,15 +27,14 @@

declare(strict_types=1);

namespace Tests\Conjoon\Illuminate\Auth\Imap;
namespace Tests\Conjoon\Illuminate\Auth;

use Conjoon\Illuminate\Auth\Imap\ImapUserProvider;
use Conjoon\Illuminate\Auth\ImapUserProvider;
use Illuminate\Contracts\Auth\UserProvider;
use Tests\TestCase;

/**
* Class ImapUserProviderTest
* @package Tests\Conjoon\Illuminate\Auth\Imap
* Tests ImapUserProvider.
*/
class ImapUserProviderTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,16 +27,15 @@

declare(strict_types=1);

namespace Tests\Conjoon\Illuminate\Auth\Imap;
namespace Tests\Conjoon\Illuminate\Auth;

use Conjoon\Illuminate\Auth\Imap\ImapUser;
use Conjoon\Mail\Client\Data\MailAccount;
use Conjoon\Illuminate\Auth\ImapUser;
use Illuminate\Contracts\Auth\Authenticatable;
use Tests\TestCase;

/**
* Class ImapUserTest
* @package Tests\Conjoon\Illuminate\Auth\Imap
* Tests ImapUser.
*/
class ImapUserTest extends TestCase
{
Expand Down
Loading
Loading