added remote db source

This commit is contained in:
Gitea
2025-06-20 19:48:09 +05:30
parent b43461e180
commit dbe6d49c49
7 changed files with 1495 additions and 5 deletions

View File

@@ -272,7 +272,11 @@ class Email extends Model
public static function parseEmail($email, $deleted = []): array
{
$messages = self::fetchEmailFromDB($email);
if (config('app.fetch_from_remote_db')) {
$messages = RemoteEmail::fetchEmailFromDB($email);
} else {
$messages = self::fetchEmailFromDB($email);
}
$limit = json_decode(config('app.settings.configuration_settings'))->fetch_messages_limit ?? 15;
$count = 1;
$response = [
@@ -282,9 +286,18 @@ class Email extends Model
foreach ($messages as $message) {
// fix for null attachments
if ($message['attachments'] === null) {
$message['attachments'] = [];
}
if (in_array($message['message_id'], $deleted)) {
// If it exists, delete the matching record from the 'emails' table
Email::where('message_id', $message['message_id'])->delete();
if (config('app.fetch_from_remote_db')) {
RemoteEmail::where('message_id', $message['message_id'])->delete();
} else {
Email::where('message_id', $message['message_id'])->delete();
}
continue;
}
@@ -331,7 +344,11 @@ class Email extends Model
file_put_contents(storage_path('logs/zemail.csv'), request()->ip() . "," . date("Y-m-d h:i:s a") . "," . $obj['sender_email'] . "," . $email . PHP_EOL, FILE_APPEND);
}
}
Email::where('message_id', $message['message_id'])->update(['is_seen' => true]);
if (config('app.fetch_from_remote_db')) {
RemoteEmail::where('message_id', $message['message_id'])->update(['is_seen' => true]);
} else {
Email::where('message_id', $message['message_id'])->update(['is_seen' => true]);
}
if (++$count > $limit) {
break;
}
@@ -404,7 +421,11 @@ class Email extends Model
public static function mailToDBStatus(): bool
{
$latestRecord = self::orderBy('timestamp', 'desc')->first();
if (config('app.fetch_from_remote_db')) {
$latestRecord = RemoteEmail::orderBy('timestamp', 'desc')->first();
} else {
$latestRecord = self::orderBy('timestamp', 'desc')->first();
}
if (!$latestRecord) {
return false;
}