Skip to content

Commit 43c2512

Browse files
Merge pull request #15 from conjoon/dev
Dev
2 parents d54c003 + 3d803e3 commit 43c2512

File tree

13 files changed

+261
-40
lines changed

13 files changed

+261
-40
lines changed

src/Illuminate/Auth/Imap/DefaultImapUserProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -30,6 +30,8 @@
3030
namespace Conjoon\Illuminate\Auth\Imap;
3131

3232
use Conjoon\Illuminate\Auth\Imap\Util as ImapUtil;
33+
use Conjoon\Illuminate\Auth\ImapUser;
34+
use Conjoon\Illuminate\Auth\ImapUserProvider;
3335
use Illuminate\Contracts\Auth\Authenticatable;
3436

3537
/**

src/Illuminate/Auth/Imap/ImapUser.php renamed to src/Illuminate/Auth/ImapUser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -27,7 +27,7 @@
2727

2828
declare(strict_types=1);
2929

30-
namespace Conjoon\Illuminate\Auth\Imap;
30+
namespace Conjoon\Illuminate\Auth;
3131

3232
use Conjoon\Mail\Client\Data\MailAccount;
3333
use Illuminate\Contracts\Auth\Authenticatable;

src/Illuminate/Auth/Imap/ImapUserProvider.php renamed to src/Illuminate/Auth/ImapUserProvider.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -27,8 +27,9 @@
2727

2828
declare(strict_types=1);
2929

30-
namespace Conjoon\Illuminate\Auth\Imap;
30+
namespace Conjoon\Illuminate\Auth;
3131

32+
use Conjoon\Illuminate\Auth\Imap\Conjoon;
3233
use Illuminate\Contracts\Auth\UserProvider;
3334

3435
/**
@@ -45,7 +46,7 @@ interface ImapUserProvider extends UserProvider
4546
* @param string $username
4647
* @param string $password
4748
*
48-
* @return Conjoon\Illuminate\Auth\Imap\ImapUser|null
49+
* @return ImapUser|null
4950
*/
5051
public function getUser(string $username, string $password): ?ImapUser;
5152
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/**
4+
* conjoon
5+
* php-lib-conjoon
6+
* Copyright (C) 2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
7+
*
8+
* Permission is hereby granted, free of charge, to any person
9+
* obtaining a copy of this software and associated documentation
10+
* files (the "Software"), to deal in the Software without restriction,
11+
* including without limitation the rights to use, copy, modify, merge,
12+
* publish, distribute, sublicense, and/or sell copies of the Software,
13+
* and to permit persons to whom the Software is furnished to do so,
14+
* subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included
17+
* in all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
declare(strict_types=1);
29+
30+
namespace Conjoon\Illuminate\Auth\LocalMailAccount;
31+
32+
use Conjoon\Illuminate\Auth\Imap\DefaultImapUserProvider;
33+
use Conjoon\Illuminate\Auth\ImapUser;
34+
use Conjoon\Mail\Client\Data\MailAccount;
35+
use Illuminate\Http\Request;
36+
37+
/**
38+
* Auth provider that expects required mailserver configurations to be available
39+
* with the payload ("x-cnmail-data"-header).
40+
*/
41+
class LocalAccountProvider extends DefaultImapUserProvider
42+
{
43+
/**
44+
* @var string
45+
*/
46+
private $payload;
47+
48+
/**
49+
* @var string
50+
*/
51+
private $mailAccountId;
52+
53+
54+
public function __construct(Request $request)
55+
{
56+
$this->payload = $request->header("x-cnmail-data");
57+
$this->mailAccountId = $request->route('mailAccountId');
58+
}
59+
60+
61+
public function getUser(string $username, string $password): ?ImapUser
62+
{
63+
$config = $this->decodePayload($this->payload);
64+
$mailAccount = $this->createMailAccount($username, $password, $config);
65+
66+
return new ImapUser($username, $password, $mailAccount);
67+
}
68+
69+
private function createMailAccount(string $username, string $password, array $config): MailAccount
70+
{
71+
$merged = array_merge($config, [
72+
"id" => $this->mailAccountId,
73+
"name" => $this->mailAccountId,
74+
"inbox_user" => $username,
75+
"inbox_password" => $password
76+
]);
77+
return new MailAccount($merged);
78+
}
79+
80+
private function decodePayload(string $payload): array
81+
{
82+
return json_decode(base64_decode($payload), true);
83+
}
84+
}

src/Mail/Client/Data/MailAccount.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -56,14 +56,14 @@
5656
* "outbox_user" => "outboxuser",
5757
* "outbox_password" => "outboxpassword',
5858
* 'outbox_secure' => "tls",
59-
* 'root' => "INBOX"
59+
* 'subscriptions' => ["INBOX"]
6060
* ]);
6161
*
6262
* $account->getOutboxSecure(); // true
6363
* $account->getInboxPort(); // 993
6464
* $account->getReplyTo(); // ['name' => 'John Smith', 'address' => '[email protected]'],
6565
*
66-
* The property "root" allows for specifying a root mailbox and defaults to "INBOX".
66+
* The property "subscriptions" allows for specifying mailbox the account is subscribed to.
6767
*
6868
* @package Conjoon\Mail\Client\Data
6969
*
@@ -82,7 +82,7 @@
8282
* @method string getOutboxAddress()
8383
* @method int getOutboxPort()
8484
* @method string getOutboxSecure()
85-
* @method array getRoot()
85+
* @method array getSubscriptions()
8686
*
8787
* @noinspection SpellCheckingInspection
8888
*/
@@ -166,7 +166,7 @@ class MailAccount implements Jsonable, Arrayable
166166
/**
167167
* @var array
168168
*/
169-
protected array $root = ["INBOX"];
169+
protected array $subscriptions = ["INBOX"];
170170

171171
/**
172172
* MailAccount constructor.
@@ -240,7 +240,7 @@ public function toArray(): array
240240
"outbox_user" => $this->getOutboxUser(),
241241
"outbox_password" => $this->getOutboxPassword(),
242242
"outbox_secure" => $this->getOutboxSecure(),
243-
"root" => $this->getRoot()
243+
"subscriptions" => $this->getSubscriptions()
244244
];
245245
}
246246

src/Mail/Client/Service/DefaultMailFolderService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -92,10 +92,10 @@ public function getMailClient(): MailClient
9292
/**
9393
* @inheritdoc
9494
*/
95-
public function getMailFolderChildList(MailAccount $mailAccount): MailFolderChildList
95+
public function getMailFolderChildList(MailAccount $mailAccount, array $subscriptions = []): MailFolderChildList
9696
{
9797
$mailFolderList = $this->getMailClient()->getMailFolderList($mailAccount);
9898

99-
return $this->getMailFolderTreeBuilder()->listToTree($mailFolderList, $mailAccount->getRoot());
99+
return $this->getMailFolderTreeBuilder()->listToTree($mailFolderList, $subscriptions);
100100
}
101101
}

src/Mail/Client/Service/MailFolderService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -40,6 +40,7 @@ interface MailFolderService
4040
* MailAccount.
4141
*
4242
* @param MailAccount $mailAccount
43+
* @param array $subscriptions
4344
*
4445
* @return MailFolderChildList An MailFolderChildList of the Mailbox-structure
4546
* found on the server.
@@ -55,7 +56,7 @@ interface MailFolderService
5556
*
5657
* @see \Horde_Imap_Client_Socket
5758
*/
58-
public function getMailFolderChildList(MailAccount $mailAccount): MailFolderChildList;
59+
public function getMailFolderChildList(MailAccount $mailAccount, array $subscriptions = []): MailFolderChildList;
5960

6061

6162
/**

tests/Illuminate/Auth/Imap/DefaultImapUserProviderTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -30,14 +30,13 @@
3030
namespace Tests\Conjoon\Illuminate\Auth\Imap;
3131

3232
use Conjoon\Illuminate\Auth\Imap\DefaultImapUserProvider;
33-
use Conjoon\Illuminate\Auth\Imap\ImapUser;
34-
use Conjoon\Illuminate\Auth\Imap\ImapUserProvider;
3533
use Conjoon\Mail\Client\Data\MailAccount;
34+
use Conjoon\Illuminate\Auth\ImapUser;
35+
use Conjoon\Illuminate\Auth\ImapUserProvider;
3636
use Tests\TestCase;
3737

3838
/**
39-
* Class DefaultImapUserProviderTest
40-
* @package Tests\Conjoon\Illuminate\Auth\Imap
39+
* Tests DefaultImapUserProvider.
4140
*/
4241
class DefaultImapUserProviderTest extends TestCase
4342
{

tests/Illuminate/Auth/Imap/ImapUserProviderTest.php renamed to tests/Illuminate/Auth/ImapUserProviderTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -27,15 +27,14 @@
2727

2828
declare(strict_types=1);
2929

30-
namespace Tests\Conjoon\Illuminate\Auth\Imap;
30+
namespace Tests\Conjoon\Illuminate\Auth;
3131

32-
use Conjoon\Illuminate\Auth\Imap\ImapUserProvider;
32+
use Conjoon\Illuminate\Auth\ImapUserProvider;
3333
use Illuminate\Contracts\Auth\UserProvider;
3434
use Tests\TestCase;
3535

3636
/**
37-
* Class ImapUserProviderTest
38-
* @package Tests\Conjoon\Illuminate\Auth\Imap
37+
* Tests ImapUserProvider.
3938
*/
4039
class ImapUserProviderTest extends TestCase
4140
{

tests/Illuminate/Auth/Imap/ImapUserTest.php renamed to tests/Illuminate/Auth/ImapUserTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* conjoon
55
* php-lib-conjoon
6-
* Copyright (C) 2019-2022 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
6+
* Copyright (C) 2019-2023 Thorsten Suckow-Homberg https://github.com/conjoon/php-lib-conjoon
77
*
88
* Permission is hereby granted, free of charge, to any person
99
* obtaining a copy of this software and associated documentation
@@ -27,16 +27,15 @@
2727

2828
declare(strict_types=1);
2929

30-
namespace Tests\Conjoon\Illuminate\Auth\Imap;
30+
namespace Tests\Conjoon\Illuminate\Auth;
3131

32-
use Conjoon\Illuminate\Auth\Imap\ImapUser;
3332
use Conjoon\Mail\Client\Data\MailAccount;
33+
use Conjoon\Illuminate\Auth\ImapUser;
3434
use Illuminate\Contracts\Auth\Authenticatable;
3535
use Tests\TestCase;
3636

3737
/**
38-
* Class ImapUserTest
39-
* @package Tests\Conjoon\Illuminate\Auth\Imap
38+
* Tests ImapUser.
4039
*/
4140
class ImapUserTest extends TestCase
4241
{

0 commit comments

Comments
 (0)