Changeset View
Changeset View
Standalone View
Standalone View
src/app/Backends/Roundcube.php
<?php | <?php | ||||
namespace App\Backends; | namespace App\Backends; | ||||
use Illuminate\Support\Facades\DB; | use Illuminate\Support\Facades\DB; | ||||
use Illuminate\Support\Facades\Storage; | use Illuminate\Support\Facades\Storage; | ||||
class Roundcube | class Roundcube | ||||
{ | { | ||||
private const FILESTORE_TABLE = 'filestore'; | private const FILESTORE_TABLE = 'filestore'; | ||||
private const USERS_TABLE = 'users'; | private const USERS_TABLE = 'users'; | ||||
private const IDENTITIES_TABLE = 'identities'; | |||||
/** @var array List of GnuPG files to store */ | /** @var array List of GnuPG files to store */ | ||||
private static $enigma_files = ['pubring.gpg', 'secring.gpg', 'pubring.kbx']; | private static $enigma_files = ['pubring.gpg', 'secring.gpg', 'pubring.kbx']; | ||||
/** | /** | ||||
* Return connection to the Roundcube database | * Return connection to the Roundcube database | ||||
* | * | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | public static function userId(string $email, bool $create = true): ?int | ||||
// Create a user record, without it we can't use the Roundcube storage | // Create a user record, without it we can't use the Roundcube storage | ||||
if (empty($user)) { | if (empty($user)) { | ||||
if (!$create) { | if (!$create) { | ||||
return null; | return null; | ||||
} | } | ||||
$uri = \parse_url(\config('imap.uri')); | $uri = \parse_url(\config('imap.uri')); | ||||
return (int) $db->table(self::USERS_TABLE)->insertGetId( | $user_id = (int) $db->table(self::USERS_TABLE)->insertGetId( | ||||
[ | [ | ||||
'username' => $email, | 'username' => $email, | ||||
'mail_host' => $uri['host'], | 'mail_host' => $uri['host'], | ||||
'created' => now()->toDateTimeString(), | 'created' => now()->toDateTimeString(), | ||||
], | ], | ||||
'user_id' | 'user_id' | ||||
); | ); | ||||
$username = \App\User::where('email', $email)->first()->name(); | |||||
$db->table(self::IDENTITIES_TABLE)->insert([ | |||||
'user_id' => $user_id, | |||||
'email' => $email, | |||||
'name' => $username, | |||||
'changed' => now()->toDateTimeString(), | |||||
'standard' => 1, | |||||
]); | |||||
return $user_id; | |||||
} | } | ||||
return (int) $user->user_id; | return (int) $user->user_id; | ||||
} | } | ||||
/** | /** | ||||
* Returns list of Enigma user homedir files to backup/sync | * Returns list of Enigma user homedir files to backup/sync | ||||
*/ | */ | ||||
Show All 20 Lines |