Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F121558937
D5878.1777511861.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D5878.1777511861.diff
View Options
diff --git a/src/app/Jobs/Mail/PasswordRetentionJob.php b/src/app/Jobs/Mail/PasswordRetentionJob.php
--- a/src/app/Jobs/Mail/PasswordRetentionJob.php
+++ b/src/app/Jobs/Mail/PasswordRetentionJob.php
@@ -32,8 +32,7 @@
*/
public function handle()
{
- if (!$this->user->isLdapReady() || !$this->user->isImapReady()) {
- // The account isn't ready for mail delivery
+ if (!$this->user->canReceiveMail()) {
return;
}
diff --git a/src/app/Jobs/Mail/TrialEndJob.php b/src/app/Jobs/Mail/TrialEndJob.php
--- a/src/app/Jobs/Mail/TrialEndJob.php
+++ b/src/app/Jobs/Mail/TrialEndJob.php
@@ -27,13 +27,14 @@
*/
public function handle()
{
- // Skip accounts that aren't ready for mail delivery
- if ($this->account->isLdapReady() && $this->account->isImapReady() && !$this->account->isSuspended()) {
- Helper::sendMail(
- new TrialEnd($this->account),
- $this->account->tenant_id,
- ['to' => $this->account->email]
- );
+ if (!$this->account->canReceiveMail()) {
+ return;
}
+
+ Helper::sendMail(
+ new TrialEnd($this->account),
+ $this->account->tenant_id,
+ ['to' => $this->account->email]
+ );
}
}
diff --git a/src/app/Mail/Helper.php b/src/app/Mail/Helper.php
--- a/src/app/Mail/Helper.php
+++ b/src/app/Mail/Helper.php
@@ -111,7 +111,7 @@
*/
public static function userEmails(User $user, bool $external = false): array
{
- $active = $user->isLdapReady() && $user->isImapReady();
+ $active = $user->canReceiveMail();
// Sending an email to non-(ldap|imap)-ready user will fail, skip it
// (or send to the external email only, when appropriate)
diff --git a/src/app/User.php b/src/app/User.php
--- a/src/app/User.php
+++ b/src/app/User.php
@@ -324,6 +324,18 @@
return $wallet->isController($this);
}
+ /**
+ * Check if the user can receive mail.
+ */
+ public function canReceiveMail(): bool
+ {
+ // Note: We're not checking for mailbox entitlement here as it's usually not necessary
+ // TODO: Remove the LDAP readiness check
+ return (!\config('app.with_ldap') || $this->isLdapReady())
+ && $this->isImapReady()
+ && !$this->isSuspended();
+ }
+
/**
* Contacts (global addressbook) for this user.
*
diff --git a/src/tests/Feature/UserTest.php b/src/tests/Feature/UserTest.php
--- a/src/tests/Feature/UserTest.php
+++ b/src/tests/Feature/UserTest.php
@@ -457,6 +457,21 @@
$this->assertFalse($ned->canUpdateConfig($admin));
}
+ /**
+ * Test User::canReceiveMail() method
+ */
+ public function testCanReceiveMail(): void
+ {
+ $user = $this->getTestUser('UserAccountA@UserAccount.com');
+ $this->assertFalse($user->canReceiveMail());
+
+ $user->status |= User::STATUS_IMAP_READY | User::STATUS_LDAP_READY;
+ $this->assertTrue($user->canReceiveMail());
+
+ $user->status |= User::STATUS_SUSPENDED;
+ $this->assertFalse($user->canReceiveMail());
+ }
+
/**
* Test user created/creating/updated observers
*/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 30, 1:17 AM (10 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18909639
Default Alt Text
D5878.1777511861.diff (3 KB)
Attached To
Mode
D5878: Introduce User::canReceiveMail()
Attached
Detach File
Event Timeline