|
81147
|
2820
|
13
|
2026-05-28T08:01:13.343332+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955273343_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5747399669444348317
|
-4308660606890243701
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
81144
|
NULL
|
NULL
|
NULL
|
|
81148
|
2821
|
30
|
2026-05-28T08:01:17.292119+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955277292_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"lines":[{"char_start":117,"char_count":2,"bounds":{"left":0.43051863,"top":0.0,"width":0.0026595744,"height":0.014365523}},{"char_start":119,"char_count":110,"bounds":{"left":0.43051863,"top":0.0,"width":0.28257978,"height":0.014365523}}],"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8882675618617696006
|
-4308678130356811381
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}...
|
81146
|
NULL
|
NULL
|
NULL
|
|
81149
|
2821
|
31
|
2026-05-28T08:01:18.447586+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955278447_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"lines":[{"char_start":117,"char_count":2,"bounds":{"left":0.43051863,"top":0.0,"width":0.0026595744,"height":0.014365523}},{"char_start":119,"char_count":110,"bounds":{"left":0.43051863,"top":0.0,"width":0.28257978,"height":0.014365523}}],"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
5747399669444348317
|
-4308660606890243701
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81150
|
2821
|
32
|
2026-05-28T08:01:23.350250+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955283350_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
Project
Project
New File or Directory…
Expand Selected...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"lines":[{"char_start":117,"char_count":2,"bounds":{"left":0.43051863,"top":0.0,"width":0.0026595744,"height":0.014365523}},{"char_start":119,"char_count":110,"bounds":{"left":0.43051863,"top":0.0,"width":0.28257978,"height":0.014365523}}],"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-2820440719359341157
|
-4308678130356811381
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
Project
Project
New File or Directory…
Expand Selected...
|
81149
|
NULL
|
NULL
|
NULL
|
|
81151
|
2820
|
14
|
2026-05-28T08:01:24.692833+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955284692_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-1516116588012193908
|
-6438878488516195957
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81152
|
2821
|
33
|
2026-05-28T08:01:24.588756+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955284588_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
7042218098364550308
|
-7767212893431190582
|
typing_pause
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
rapstomViewCoocWindowFV faVsco.s ~$ JY-20915-fix-missing-header-text-proidet© InternetMessagelnterface.ph© MailChannelService.phgd MeetingGeneratoranoucadorEOHUNDn Playbooks—KeCaLAJotaeoa TeamaTelechonyaUserPilotWebhookC Abstrac Semvice cho©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoeeonaraneacarhes oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.php© ResolveTeamCrmConnection.ph© SimoleThrottleService.ohd© SlackService.ohoC SocialAccountService.oho)C SoftPhoneService.ohoC TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.ohC UserSemce.on©Uuid.php> M Traitc› @ UseCases>E Va cationMo halnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnTextRelayServiceTest.phpCа а а а444 4 8 8 0 1 )1010111113.env.productionclass TextRelayService|//ockhrhttpobtze toneczon syneteascurovzas'emailprovider id' => SmessageldUSDCXKDRITROCROSNOooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUS EMATLS):osoatchi1o0Loor nfot messaco: "Textrelayservicel Successfully disoatched nessagemessaned e> Snessageo'text_relay_1d => Srelayedtext->1d,Casseaceldelte SraseadaleLog::info( message: "[TextRelayService) Sync completed", 1'nailbox" => Smailbox,'nessages processed' => count(Smessagelds)'nessage ids' => array stice(SmessageIds,offset: 8, length: 10)1):recurn shessacelosouooc tuncoon ceistoryooooleonoswnoacelokene nuLrooce conol keyt mhyroooorenaoessades eShistonyid=I if ne have no history stored. HatchkaflboxEvents nust not have run vet a1f (ShistockId == false) (Shistoruld= Sthis-sretreshttstony2osingstoosoSoarans ="startHistorud" & Shistorydlv Accept Fle x- X Reject File oxo6289%SF (iminny@localhost)HS.Jocal jiminny@blocalhost)2826-85-28 87:47:501 Local.INF0: Sparans& console [PROD# consoe leu.startHistoryId) => 359921correlazon1d:YaC0//105-c215-4442-[CREDIT_CARD]{d*:*87f39623-3deb-4827-a8cf-b862acc93289*}7826-85-28 87:47:58 Local.IWFU: SnessagchzscomvoTrace10: [CREDIT_CARD]-a8cт-0862aec93789-%17876-85028 87rS857ocetsts oaraneIhistorylypes => messageAddecstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaса 36".-62a0Rp6p-1669-hcR4-h1de-R/3ceccba6at*2826-85-28 87-58-5811 JocnlTWEn: Snessadels stomEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-85.28 87-55-17 | 1o601 TNEh• SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-d21b-4d4a-b84b-a8531ca414a7"1300x.06.29 92.66-17 1 1oc0-051: Snossaachstom.#"correlation_id":"25971837-3161-431b-adS9-e898eb49beSf*, *trace_1d*:*c3463c2c-d21b-4d4a-b84b-a8531ca614a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst Srassadelsrom#[CREDIT_CARD].05cc-H529269c24h7"TextRelayServiceTestler henwserwiet• Thu 28 May 11:01:24+0.-VANew PHP manual is available (latest: 3.0.71. Undate with doc -uodatc-eania>ssve - new class extenosminnyservices .wam lexorelyseivieepoone funcionconstuctu-iminawCanncasnliTaytrelsancssnoc.umone.t..rm> Samail = Ssvc-sgetService contialyiminny.google-textuser=G00gle|ServicelCmall (41684€The message is gone — it was likely trashed by the job's finally block (trastMessage() is called afterThe key question is: why is the warning still appearing? it means new messages keep arriving without x-Gn-0rigThe user reverted my tix (back to only checking X-ce-oriainalolo, so messages sent dircctly to catch»all+...To catch the next occurrence and inspect it before it gets trashed, you can temporarily add logging of all headersin stoncurtentenvaronbentRead TextRelayService.php #L182-211TextRelayService.ohdThis logs all header names (with + tag stripped for PlI safety) so the next time it fires you'll see in production logsOnce you see that in the logs, we'll know for certain whether re-applying the To fallback fix is the right moveOal -can I see it somewhere now on staging or productions-@ eodeAdhotvRT RetetalAcceot allMwoderlatme orerhiest4 spad...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81153
|
2821
|
34
|
2026-05-28T08:01:27.641362+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955287641_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-4528724110787610736
|
2604719229101344208
|
visual_change
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
rapstomViewCoocWindowFV faVsco.s ~$ JY-20915-fix-missing-header-text-proidet© InternetMessagelnterface.ph© MailChannelService.phgd MeetingGeneratoranoucadorEOHUNDn Playbooks—KeCaLAJotaeoa Teama TelechonyaUserPilotWebhookC Abstrac Semvice cho©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.php© ResolveTeamCrmConnection.ph© SimoleThrottleService.ohdC SlackService.ohoC SocialAccountService.oho)C SoftPhoneService.ohoC TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.ohC UserSemce.on©Uuid.php> M Traitc› @ UseCases>E Va cationMo halnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnTextRelayServiceTest.phpCа а а а444 4 8 8 001 1 )1010111113.env.productionclass TextRelayService|//ockhrhttpobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldUSDCAKDIRIUSPROCROSNOooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUE.EMATLS):osoatchis1o0)Loor nfot messaco:"Textrelavseryicel Successfully disoatched nessage"messaned e> Snessageo'text_relay_1d => Srelayedtext->1d,Casseaceldelte SraseadaleLog::info( message: "[TextRelayService) Sync completed", 1'nailbox" => Smailbox,'nessages processed' => count(Smessagelds)'nessage ids' => array stice(SmessageIds,offset: 8, length: 10)1):recurn shessacelosouooc tuncoon cecostory ooooleonosemeehimoacelokene nuLrooce conol keyt mhyroooolrenenevooessades eShistonyid=I if ne have no history stored. HatchkaflboxEvents nust not have run vet a1f (ShistockId == false) (Shistoruld= Sthis-sretreshttstony2osingstoosoSoarans ="startHistorud' & Shiistonydlv Accept Fle x- X Reject File oxo6289%SF (iminny@localhost)HS.Jocal jiminny@blocalhost)2826-85-28 87:47:501 Local.INF0: Sparans& console [PROD& console (EU)anler herseietS0100% 142-• Thu 28 May 11:01:27TextRelayServiceTest+0 .2V2Acan I see it somewhere now on staging or productionstartHistoryId) => 359921correlazon10:YaC0//105-02415-4442-[CREDIT_CARD]{d":*87f39623-3deb-4827-a8cf-b862aec93289**7826-85-28 87:47:58 Local.IWFU: SnessagchzscomvoTrace10: [CREDIT_CARD]-a8cт-0862aec93789-17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaса 36".-62a0Rp6p-1669-hcR4-h1de-R/3ceccba6at*2826-85-28 87-58-5811 JocnlTWEn: Snessadels stomEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "tлaCA S/.-6290R0/9-1640-hc04-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-d21b-4d4a-b84b-a8531ca414a7"1300x.06.29 92-66-171 Jocol-1w51: Snossagchs stom."correlation_id":"25971837-3161-431b-adS9-e898eb48bASf* *trace_id*:*c3463c2c-d21b-4d4a-b84b-a8531ca414a7*}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst Srassadelsrom#[CREDIT_CARD].05cc-H529269c24h7"AReinctalAcceot alllamahienuatAdhotisMwoderlatme oerireshensa....
|
81152
|
NULL
|
NULL
|
NULL
|
|
81154
|
2821
|
35
|
2026-05-28T08:01:36.954424+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955296954_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"lines":[{"char_start":117,"char_count":2,"bounds":{"left":0.43051863,"top":0.0,"width":0.0026595744,"height":0.014365523}},{"char_start":119,"char_count":110,"bounds":{"left":0.43051863,"top":0.0,"width":0.28257978,"height":0.014365523}}],"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
8882675618617696006
|
-4308678130356811381
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
2
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81156
|
2821
|
36
|
2026-05-28T08:01:48.404346+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955308404_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
FircroxhsttonPwovscors$2 JY-20915-fix-m© InternetM FircroxhsttonPwovscors$2 JY-20915-fix-m© InternetMessagelnterface.ph© MailChannelService.phgd MeetingGeneratoranoucadorEOHUNDn Playbook—KeCaLAJotaeoa Team#UserPilotWebhookC Abstrac Semvice cho©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpe PocAlvo TosmermEMЛodiA ny© Simole ThrottleService.ohd© SlackService.ohdC SocialAccountService.oho)C SoftPhoneService.ohoC TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.ohC UserSemce.on©Uuid.php> M Traitc› L UseCasese ValaationWa holnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnWindowHelp© SyncMailbox.phpockhrhttTextRelayServiceTest.phpfyminny.ohe3.env.productionclass TextRelayServicepobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldTUSDEXKLOYDINIUNTROCROSNOРОааатТтаааамаакамаа88 ) рр ) нанн186ooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUE EMATLS)|//osoatchis1o0)Loor nfot messaco: "Textrelayservicel Successfully disoatched nessagemessaned e> Snessageo'text_relay_1d => Srelayedtext->1d,Caaseaceldelte Smaceacal.eLog::info( message: "[TextRelayService) Sync completed", u'nailbox" => Smailbox,'nessages processed' => count(Smessagelds)'nessage ids' => array stice(SmessageIds,offset: 8,length: 10)1):recurn shessacelosouooc tuncoon ceco story oooeleonoseeeehnimaoacelokene nuLressades eaistoryeott me have no mistory stoned, narchier boxevents nust not have run vereaif (Shistoryld == false) {Shistoruld=sthis-sretreshisconyposingstooscSoanans = f- nas.lakylak.xyz/desktop/mcustomuio *sravelloA SFLA console (STAGING2826-85-28 87:47:501 locahistoryTypes => messstartHistoryId) => 359corretatzon1d: yacc/(2826-85-28 87:47:581 LocaDXP4800PLUS-B5FEGarmin DashboargNew TabNow ThdFiesCloud DrivesFile Version ExplorerN0866560Arraycorrelation.1d":"%accy17876-85078 87-5885711Roclhistorylypes > messstantthstorwioil"cornellatsion sd"."oht7h2826-85-28 R7-59-5811 1ocol{"correlation_id":"ebf742924-05-28 07-55-17 | 16cnlArrayhistoryTypes = messCwAtN&AtAAuTAlC2G12826-85-28 87:55:171 LocalArracorrelatton.1d":"759%12826-85-28 88:88:531 locaArravmistoryvoes s> nessaIstartHistoryidl s 359conne anion sa"e"daosyON-HLOR RROARESAIRIOCOEconnalation Sdw.*da057)Control PanelAoo eenterLox's?SupporTask Manageon ne ofictToyiEaausl Mlach nemwwuninadcDLNAVaulSnapshotComicSync & Backup100% 142-• Thu 28 May 11:01:47.UGREEN AI...
|
NULL
|
-2016968022510171466
|
NULL
|
click
|
ocr
|
NULL
|
FircroxhsttonPwovscors$2 JY-20915-fix-m© InternetM FircroxhsttonPwovscors$2 JY-20915-fix-m© InternetMessagelnterface.ph© MailChannelService.phgd MeetingGeneratoranoucadorEOHUNDn Playbook—KeCaLAJotaeoa Team#UserPilotWebhookC Abstrac Semvice cho©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpe PocAlvo TosmermEMЛodiA ny© Simole ThrottleService.ohd© SlackService.ohdC SocialAccountService.oho)C SoftPhoneService.ohoC TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.ohC UserSemce.on©Uuid.php> M Traitc› L UseCasese ValaationWa holnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnWindowHelp© SyncMailbox.phpockhrhttTextRelayServiceTest.phpfyminny.ohe3.env.productionclass TextRelayServicepobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldTUSDEXKLOYDINIUNTROCROSNOРОааатТтаааамаакамаа88 ) рр ) нанн186ooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUE EMATLS)|//osoatchis1o0)Loor nfot messaco: "Textrelayservicel Successfully disoatched nessagemessaned e> Snessageo'text_relay_1d => Srelayedtext->1d,Caaseaceldelte Smaceacal.eLog::info( message: "[TextRelayService) Sync completed", u'nailbox" => Smailbox,'nessages processed' => count(Smessagelds)'nessage ids' => array stice(SmessageIds,offset: 8,length: 10)1):recurn shessacelosouooc tuncoon ceco story oooeleonoseeeehnimaoacelokene nuLressades eaistoryeott me have no mistory stoned, narchier boxevents nust not have run vereaif (Shistoryld == false) {Shistoruld=sthis-sretreshisconyposingstooscSoanans = f- nas.lakylak.xyz/desktop/mcustomuio *sravelloA SFLA console (STAGING2826-85-28 87:47:501 locahistoryTypes => messstartHistoryId) => 359corretatzon1d: yacc/(2826-85-28 87:47:581 LocaDXP4800PLUS-B5FEGarmin DashboargNew TabNow ThdFiesCloud DrivesFile Version ExplorerN0866560Arraycorrelation.1d":"%accy17876-85078 87-5885711Roclhistorylypes > messstantthstorwioil"cornellatsion sd"."oht7h2826-85-28 R7-59-5811 1ocol{"correlation_id":"ebf742924-05-28 07-55-17 | 16cnlArrayhistoryTypes = messCwAtN&AtAAuTAlC2G12826-85-28 87:55:171 LocalArracorrelatton.1d":"759%12826-85-28 88:88:531 locaArravmistoryvoes s> nessaIstartHistoryidl s 359conne anion sa"e"daosyON-HLOR RROARESAIRIOCOEconnalation Sdw.*da057)Control PanelAoo eenterLox's?SupporTask Manageon ne ofictToyiEaausl Mlach nemwwuninadcDLNAVaulSnapshotComicSync & Backup100% 142-• Thu 28 May 11:01:47.UGREEN AI...
|
81154
|
NULL
|
NULL
|
NULL
|
|
81175
|
NULL
|
0
|
2026-05-28T08:03:01.348521+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955381348_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
rapstomViewCoocWindowFV faVsco.s ~$ JY-20915-fix-m rapstomViewCoocWindowFV faVsco.s ~$ JY-20915-fix-missing-header-text-ockhrhtt© InternetMessagelnterface.ph© MailChannelService.phgTextRelayServiceTest.php3.env.productionclass TextRelayServiced MeetingGeneratoranoucadorpobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldEOHUNDn PlaybooksUSDCAKDIRIUSPROCROSNO—KeCaLAJotaeoooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUS EMATLS):a TeamaTelechony|//osoatchis1o0)#UserPilotWebhookLoor infot messaco:"Textrelavseryicel Successfully dispatched nessage".C Abstrac Semvice cho©ActivitvProviderFactory.ohomessaned e> Snessageo'text_relay_1d => Srelayedtext->1d,© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeCasseaceldelte SraseadaleC IpapiClient.phpC IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpe PocAlvo TosmermEMЛodiA nyLog::info( message: "[TextRelayService) Sync completed", 1'nailbox" => Smailbox,'nessages processed' => count(Smessagelds)'nessage ids' => array stice(SmessageIds,offset: 8, length: 10)recurn shessacelos© SimoleThrottleService.ohd© SlackService.ohdC SocialAccountService.oho)C SoftPhoneService.ohoouooc tuncoon ceistoryooooleonoswnoacel okene NuLLhooce conol koytnyroooolrena0oC TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.oh95essades eaistoryeC Use Semce ono©Uuid.php> M Traitc› @ UseCases99I if ne have no history stored. HatchkaflboxEvents nust not have run vet a1f (ShistockId == false) (Shistoruld= Sthis-sretreshttstony2osingstoosoSoarans =>E Va cation"startHistorud" & ShistorydlMo halnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnv Accept Fle xeX Reject File oxd6289%SF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD# consoe leu.2826-85-28 87:47:501 Local.INF0: SparansstartHistoryId) => 359921correlazon1d:YaC0//105-c215-4442-[CREDIT_CARD]{d":*87f39623-3deb-4827-a8cf-b862aec93289**7826-85-28 87:47:58 Local.IWFU: SnessagchzscomvoTrace10: [CREDIT_CARD]-a8cт-0862aec93789-%17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaса 36".-62a0Rp6p-1669-hcR4-h1de-R/3ceccba6at*2826-85-28 R7-59-5811 1oclTNED: Snessadels stomuEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-d21b-4d4a-b84b-a8531ca414a7"1300x.06.29 92-66-171 Jocol-1w51: Snossagchs stom.#"correlation_id":"25971837-3161-431b-adS9-e898eb49beSf*, *trace_1d*:*c3463c2c-d21b-4d4a-b84b-a8531ca414a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst Srassadelsrom#[CREDIT_CARD].05cc-H529269c24h7"TO0У L7oo inu comoy tirus.uTextRelayServiceTestrner hensewietCinlishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and nits a message without X.e-oriainal-o, the warning will now include besaeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch torTextRelaySerice Refused nesssoe: miosina Xec orinins -lo hesdeThe log entry will now look like"Delivered-To: catch-all""To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequentyScarched text.Tineschtouettkewtnseo.torescheotlineoloworconto..incommnotrhorkrexcrelav:svmc=volcan trigger it manually right now on staging/production to get the new log output immediatelyb basdocker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nw/hrseashntsrrau.ntho/warninalaaimmodintoh Marashthwetmthaehhaainnt emahienuAiN-@ eodeAdhotisAcceot all• Cuwndeuleime arelhires2 4 space...
|
NULL
|
5810508792279950501
|
NULL
|
visual_change
|
ocr
|
NULL
|
rapstomViewCoocWindowFV faVsco.s ~$ JY-20915-fix-m rapstomViewCoocWindowFV faVsco.s ~$ JY-20915-fix-missing-header-text-ockhrhtt© InternetMessagelnterface.ph© MailChannelService.phgTextRelayServiceTest.php3.env.productionclass TextRelayServiced MeetingGeneratoranoucadorpobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldEOHUNDn PlaybooksUSDCAKDIRIUSPROCROSNO—KeCaLAJotaeoooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUS EMATLS):a TeamaTelechony|//osoatchis1o0)#UserPilotWebhookLoor infot messaco:"Textrelavseryicel Successfully dispatched nessage".C Abstrac Semvice cho©ActivitvProviderFactory.ohomessaned e> Snessageo'text_relay_1d => Srelayedtext->1d,© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeCasseaceldelte SraseadaleC IpapiClient.phpC IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpe PocAlvo TosmermEMЛodiA nyLog::info( message: "[TextRelayService) Sync completed", 1'nailbox" => Smailbox,'nessages processed' => count(Smessagelds)'nessage ids' => array stice(SmessageIds,offset: 8, length: 10)recurn shessacelos© SimoleThrottleService.ohd© SlackService.ohdC SocialAccountService.oho)C SoftPhoneService.ohoouooc tuncoon ceistoryooooleonoswnoacel okene NuLLhooce conol koytnyroooolrena0oC TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.oh95essades eaistoryeC Use Semce ono©Uuid.php> M Traitc› @ UseCases99I if ne have no history stored. HatchkaflboxEvents nust not have run vet a1f (ShistockId == false) (Shistoruld= Sthis-sretreshttstony2osingstoosoSoarans =>E Va cation"startHistorud" & ShistorydlMo halnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnv Accept Fle xeX Reject File oxd6289%SF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD# consoe leu.2826-85-28 87:47:501 Local.INF0: SparansstartHistoryId) => 359921correlazon1d:YaC0//105-c215-4442-[CREDIT_CARD]{d":*87f39623-3deb-4827-a8cf-b862aec93289**7826-85-28 87:47:58 Local.IWFU: SnessagchzscomvoTrace10: [CREDIT_CARD]-a8cт-0862aec93789-%17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaса 36".-62a0Rp6p-1669-hcR4-h1de-R/3ceccba6at*2826-85-28 R7-59-5811 1oclTNED: Snessadels stomuEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-d21b-4d4a-b84b-a8531ca414a7"1300x.06.29 92-66-171 Jocol-1w51: Snossagchs stom.#"correlation_id":"25971837-3161-431b-adS9-e898eb49beSf*, *trace_1d*:*c3463c2c-d21b-4d4a-b84b-a8531ca414a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst Srassadelsrom#[CREDIT_CARD].05cc-H529269c24h7"TO0У L7oo inu comoy tirus.uTextRelayServiceTestrner hensewietCinlishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and nits a message without X.e-oriainal-o, the warning will now include besaeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch torTextRelaySerice Refused nesssoe: miosina Xec orinins -lo hesdeThe log entry will now look like"Delivered-To: catch-all""To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequentyScarched text.Tineschtouettkewtnseo.torescheotlineoloworconto..incommnotrhorkrexcrelav:svmc=volcan trigger it manually right now on staging/production to get the new log output immediatelyb basdocker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nw/hrseashntsrrau.ntho/warninalaaimmodintoh Marashthwetmthaehhaainnt emahienuAiN-@ eodeAdhotisAcceot all• Cuwndeuleime arelhires2 4 space...
|
81174
|
NULL
|
NULL
|
NULL
|
|
81379
|
2825
|
81
|
2026-05-28T08:12:28.654310+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955948654_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
6294803774282181717
|
-4236620260367218295
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81380
|
2824
|
49
|
2026-05-28T08:12:31.659187+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955951659_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up todate for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/q438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations → docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files per process.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MBmemory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:12:31Describe what you are looking for* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
6517438038562715677
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up todate for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/q438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations → docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files per process.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MBmemory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:12:31Describe what you are looking for* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81381
|
2825
|
82
|
2026-05-28T08:12:31.549955+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955951549_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
rapstomCoocFV faVsco.|s ~$ JY-20915-fix-missing-he rapstomCoocFV faVsco.|s ~$ JY-20915-fix-missing-header-text© InternetMessagelnterface.phcMaenanneiservice.ord MeetingGeneratoranoucadorEOHUNDn Playbooks—KeCaLAJotaeoa Team#UserPilotWebhookC AbstractSemvice cno©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpaparicioantShareServicc.ong©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpe PocAlvo TosmermEMЛodiA ny© SimoleThrottleService.ohd© SlackService.ohoC SocialAccountService.oho)C SoftPhoneService.ohoC TeamOwnerService.ohocertWichonoC) TranscodeParameterResolver.ohC UserSemce.onC Uiidioho> M Traitc› @ UseCasese ValaationWa holnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnockhrhtt3.env.productioncloss lexckela servactRaSS8989889e8983a3222aapobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldUSDCXKDRITROCROSNOooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUS EMATLS):dispatch(Siob):unsoarchi 100Log::info( message: '[TextRelayService) Successfully dispatched nessage. L"messane "d' = Shessaceidl"text_relay_id' => SrelayedText->id,quene' => Constante.- MiFllF ERATIS)SnessageIds(l = Smessageld;Log::info( message:""TextRelayService) Sync completed". 0aoLoox = aokoox"acaceorocsoe s coontsaeos"nessage ids' => array slice(Snessageids.offset: 6,length: 10).oubluic function cettistoryi soog esnor Sservice): arrawSpageroken = null;Stopic = confad key: "minny, coogile text relay tootc'oSmessages = LJ:Sanistonuiderache:toetmonte/ If we have no history stored, latchhaflboxEvents nust not have run yet :1f (Shisterkid u false) (Shsetonvin=Whecsnatnaehh.exonucos.orwoarleSparans = 0abfetonvTunnet es IesecsaoAddodeIctantHfetonuldi es ChictonutaltZorzcditsv Accept Fle x- X Reject File oxoSF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD# consoe leu.2826-85-28 87:47:501 Local.INF0: SparansstartHistoryId) => 359921correlazon10:YaC0//105-02715-4442-8886-726a82358090-"trace.1d*: *87f39623-3deb-4827-a8cf-b862aec93289**17826-85-28 87:47:58 Local.wFu: Snessagchzscory2090rac010: [CREDIT_CARD]-a8cт-0862aec93789-517876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaса 36".-62a0Rp6p-1669-hcR4-h1de-R/3ceccba6at*2826-85-28 R7-59-5811 1oclTNED: Snessadels stomuEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 260023f63c2c-d21b-4d4a-b84b-a8531ca414a7"1300x.06.29 92.66-17 1 1oc0-051: Snossaachstom.#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_id*:*c3463c2c-d21b-4d4a-b84b-a8531ca614a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst SrassadelsromEconnalatton Sdw::4a057707.4728-4h47-8.77-061с9еса120св воласа S/".:36682470.7042-1566.05cc-h52026Ac24h7"2924-85-28 98-05-27| Jocol TNSh• SoananeTO0У L7• Thu 28 May 11:12:31TextRelayServiceTestrner hensewietCiniishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and hits a message without X-e-original-lo, the warning will now include teaoeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• oTextRelaySerice Refused nesssoe: miosina Xec orinins -lo hesdeThe log entry will now look like"Delivered-To: catch-all""To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequentyineschtouletkewinseo.tarescnectlineoloworconto.thcommnotsrhorttex.erclav.swmx=yolcan trigger it manually right now on staging/production to get the new log output immediately:docker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nAihm aeashnterraun tho warnina lon mmadistow a rash tanetwths eaharinin1tile +2-1nt emahienuAiN—@ eodeC AdaotivAcceot alluwndeuleime arelhirest4 space...
|
NULL
|
1600019154409804412
|
NULL
|
click
|
ocr
|
NULL
|
rapstomCoocFV faVsco.|s ~$ JY-20915-fix-missing-he rapstomCoocFV faVsco.|s ~$ JY-20915-fix-missing-header-text© InternetMessagelnterface.phcMaenanneiservice.ord MeetingGeneratoranoucadorEOHUNDn Playbooks—KeCaLAJotaeoa Team#UserPilotWebhookC AbstractSemvice cno©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpaparicioantShareServicc.ong©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpe PocAlvo TosmermEMЛodiA ny© SimoleThrottleService.ohd© SlackService.ohoC SocialAccountService.oho)C SoftPhoneService.ohoC TeamOwnerService.ohocertWichonoC) TranscodeParameterResolver.ohC UserSemce.onC Uiidioho> M Traitc› @ UseCasese ValaationWa holnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnockhrhtt3.env.productioncloss lexckela servactRaSS8989889e8983a3222aapobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldUSDCXKDRITROCROSNOooa new twexNelayerssacdoryeoenSiob->onQueue( queue: Constants:: QUEUS EMATLS):dispatch(Siob):unsoarchi 100Log::info( message: '[TextRelayService) Successfully dispatched nessage. L"messane "d' = Shessaceidl"text_relay_id' => SrelayedText->id,quene' => Constante.- MiFllF ERATIS)SnessageIds(l = Smessageld;Log::info( message:""TextRelayService) Sync completed". 0aoLoox = aokoox"acaceorocsoe s coontsaeos"nessage ids' => array slice(Snessageids.offset: 6,length: 10).oubluic function cettistoryi soog esnor Sservice): arrawSpageroken = null;Stopic = confad key: "minny, coogile text relay tootc'oSmessages = LJ:Sanistonuiderache:toetmonte/ If we have no history stored, latchhaflboxEvents nust not have run yet :1f (Shisterkid u false) (Shsetonvin=Whecsnatnaehh.exonucos.orwoarleSparans = 0abfetonvTunnet es IesecsaoAddodeIctantHfetonuldi es ChictonutaltZorzcditsv Accept Fle x- X Reject File oxoSF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD# consoe leu.2826-85-28 87:47:501 Local.INF0: SparansstartHistoryId) => 359921correlazon10:YaC0//105-02715-4442-8886-726a82358090-"trace.1d*: *87f39623-3deb-4827-a8cf-b862aec93289**17826-85-28 87:47:58 Local.wFu: Snessagchzscory2090rac010: [CREDIT_CARD]-a8cт-0862aec93789-517876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaса 36".-62a0Rp6p-1669-hcR4-h1de-R/3ceccba6at*2826-85-28 R7-59-5811 1oclTNED: Snessadels stomuEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 260023f63c2c-d21b-4d4a-b84b-a8531ca414a7"1300x.06.29 92.66-17 1 1oc0-051: Snossaachstom.#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_id*:*c3463c2c-d21b-4d4a-b84b-a8531ca614a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst SrassadelsromEconnalatton Sdw::4a057707.4728-4h47-8.77-061с9еса120св воласа S/".:36682470.7042-1566.05cc-h52026Ac24h7"2924-85-28 98-05-27| Jocol TNSh• SoananeTO0У L7• Thu 28 May 11:12:31TextRelayServiceTestrner hensewietCiniishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and hits a message without X-e-original-lo, the warning will now include teaoeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• oTextRelaySerice Refused nesssoe: miosina Xec orinins -lo hesdeThe log entry will now look like"Delivered-To: catch-all""To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequentyineschtouletkewinseo.tarescnectlineoloworconto.thcommnotsrhorttex.erclav.swmx=yolcan trigger it manually right now on staging/production to get the new log output immediately:docker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nAihm aeashnterraun tho warnina lon mmadistow a rash tanetwths eaharinin1tile +2-1nt emahienuAiN—@ eodeC AdaotivAcceot alluwndeuleime arelhirest4 space...
|
81379
|
NULL
|
NULL
|
NULL
|
|
81382
|
2825
|
83
|
2026-05-28T08:12:34.405435+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955954405_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
6294803774282181717
|
-4236620260367218295
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81383
|
2824
|
50
|
2026-05-28T08:12:34.506513+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955954506_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
6294803774282181717
|
-4236620260367218295
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
81380
|
NULL
|
NULL
|
NULL
|
|
81384
|
2825
|
84
|
2026-05-28T08:12:39.146335+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955959146_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
6012954090851792802
|
-4236620260367218295
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected...
|
81382
|
NULL
|
NULL
|
NULL
|
|
81385
|
2825
|
85
|
2026-05-28T08:12:40.913383+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955960913_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
144275118766944746
|
-4236620260350441079
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81386
|
2825
|
86
|
2026-05-28T08:12:42.283944+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779955962283_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
6294803774282181717
|
-4236620260367218295
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
81385
|
NULL
|
NULL
|
NULL
|
|
81405
|
2827
|
0
|
2026-05-28T08:13:38.693983+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956018693_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n // dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
6294803774282181717
|
-4236620260367218295
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81406
|
2826
|
0
|
2026-05-28T08:13:41.893364+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956021893_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV ( SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up to date for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/‹438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations + docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files perprocess.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MB memory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:13:41Describe what you are looking for* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
5875988546472891385
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV ( SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up to date for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/‹438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations + docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files perprocess.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MB memory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:13:41Describe what you are looking for* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81407
|
2826
|
1
|
2026-05-28T08:13:43.831557+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956023831_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n// dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7170854067297703171
|
-4236620260367218295
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
// dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
81406
|
NULL
|
NULL
|
NULL
|
|
81408
|
2827
|
1
|
2026-05-28T08:13:41.999603+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956021999_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-1752890267531063518
|
-6618672614029721119
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
rapstomCoocWindowFV faVsco.|s ~$ JY-20915-fix-missing-header-text© InternetMessagelnterface.phcMaenanneiservice.ord MeetingGeneratoranoucadorEOHUNDn Playbooks—KeCaLAJotaeoa Team#UserPilotWebhookC Abstrac Semvice cho©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpaparicioantShareServicc.ong©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpe PocAlvo TosmermEMЛodiA ny© SimoleThrottleService.ohg© SlackService.ohoC SocialAccountService.oho)C SoftPhoneService.ohoC TeamOwnerService.ohoeearwtWictoneC) TranscodeParameterResolver.ohC UserSemce.onC Uuidloho> M Traitc› @ UseCasese ValcatiorWa holnore nhr@ tnitislGrantondGtnto nhoelliminnv nhaockhrhttTextRelayServiceTest.phpcloss lexckela servact06888082REARKRRERR85S38885848682282688pobtze tuneczon synelyiancarovror'emailprovider id' => SmessageldUSDCXKDRITROCROSNOopa newtwexNelayaessaeronwolexeSiob->onQueue( queue: Constants:: QUEUE EMATLS)dispatch(Siob):unsoarchi 100Log::info( message: '[TextRelayService) Successfully dispatched nessage. L"messane "d' = Shessaceidl"text_relay_id' => SrelayedText->id,quene' => Constante.- MiFllF ERATIS)SnessageIds(l = Smessageld;Log::info( message:""TextRelayService) Sync completed". 0aoLoox = aokoox"acaceorocsoe s coontsaeos"nessage ids' => array slice(Snessageids.offset: 6,lenath: 10)oubluic function cettistoryi soog esnor Sservice): arrawSpageroken = null;Stopic = confad key: "minny, coogile text relay tootc'oSmessages = LJ:Sauistonuiderache:toetmonteDte ne have nomsrony croned narcotasilboy wente euet oor have min var*1f (Shisterkid u false) (Shsetonvin=Whecsnatnaehh.exonucos.orwoarleSparans =abfetonvTunnet es IesccsaaAddad*IctantHSetonuldt es ChictonutaltZorzcditsv Accept Fle x- X Reject File oxoSF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD# consoe leu.2826-85-28 87:47:501 Local.INF0: SparansstartHistoryId) => 359921correlazon1d:YaC0//105-c2715-4442-[CREDIT_CARD]-"trace.1d*: *87f39623-3deb-4827-a8cf-b862aec93289**17826-85-28 87:47:58 Local.wFu: Snessagchzscory2090rac010: [CREDIT_CARD]-a8cт-0862aec93789-517876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaса 36".-62a0Rp6p-1669-hcR4-h1de-R/3ceccba6at*2826-85-28 R7-59-581 1ocnl-TNEn: Snessadels stomEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 260023f63c2c-d21b-4d4a-b84b-a8531ca414a7"1300x.06.29 92.66-17 1 1oc0-051: Snossaachstom.#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_id*:*c3463c2c-d21b-4d4a-b84b-a8531ca614a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes > messageaddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst SrassadelsromEconnalatton Sdw::4a057707.4728-4h47-8.77-061с9еса120св воласа S/".:36682470.7042-1566.05cc-h52026Ac24h7"2924-85-28 98-05-27| Jocol TNSh• SoananeTO0У L7• Thu 28 May 11:13:41TextRelayServiceTestrner hensewietCiniishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and hits a message without X-e-original-lo, the warning will now include teaoeis prescht in the log contexthck it in Cloud Watch or wherever woduetionistac na loos go)l Sasrch tog• oTextRelaySeruice Refused message: miosing Xec orioins -to hesdeThe log entry will now look like"Delivered-To: catch-all""o: catchesl"The Sync runs on a schedule = check kernel pho to see now trequentySearched text.rineschtouletkewinseo.tarescnectlineoloworconto.thcommnotsrhorttex.erclav.swmx=yolcan trigger it manually right now on staging/production to get the new log output immediately:docker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nahrAeachntsrrau.n thowarninaloammodistow MarashtawetwthscehhahiCan I maybe fetch it form the omail.- @ CodnC AdaotivAcceot alluwndeuleime arelhireht4 spac...
|
81405
|
NULL
|
NULL
|
NULL
|
|
81409
|
2827
|
2
|
2026-05-28T08:13:46.645363+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956026645_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-8510908486457674102
|
-4236620329338353269
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$params ' . PHP_EOL . print_r($params, true));
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81410
|
2826
|
2
|
2026-05-28T08:13:46.747938+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956026747_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up todate for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/q438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations → docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files per process.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MBmemory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:13:46Describe what you are looking for®* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
7317195534455997791
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up todate for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/q438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations → docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files per process.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MBmemory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:13:46Describe what you are looking for®* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81411
|
2827
|
3
|
2026-05-28T08:13:50.863042+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956030863_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
PhpStormViewFV faVsco.s$ JY-20915-fix-missProinet PhpStormViewFV faVsco.s$ JY-20915-fix-missProinet v© InternetMessagelnterface.ph© MailChannelService.phgo Textrelkysewice.on0 MeetinaGeneratoia Notificationên OAuth2in Playbooks—KeCaLA—oeourvastaeoDn Streamingla Teama Telechony#[EMAIL]@ ApiResponseService.ohdeeonaraneacarhes oodclineehCaatswies donC InstantMeetingService.phgcilntecomswneoeC IpapiClient.phplpapiService.phpC ParticipantShareService.phg© PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpel PocAlvoTosmErmEmЛodiA ny© SimoleThrottleService.ohg© SlackService.ohd© SoclalAccountService.oho)© SoftPhoneService.ohd©) TeamDeactivatedService.oho©) TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.ohC UserSemce.onC Uuidloho> M Traitc@ UseCasesCodKelucioRurToolWindowKerodtoh© SyncMailbox.phpcomposeriyorDockerfileTextRelayServiceTest.phpphp fiminny.php.env.productionclass TextRelayServiceНВННВНЦВВВВВВВВВВВВВжа3а5кUtilse ValaationivoWa holnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnA Olen nhi149146suoere Tuncczon cechzstomy oodeccondzt sscmizce, drneShistoryld// If we have no history stored, WatchMailboxEvents must not have run yet :/if (Shistomwd. aa talse) 1Shistoryld = $this->refreshHistoryPoint(Stopic):Sparans = ['historyTypes' => 'messageAdded""stantlstonutal => Shástonuialdoif (SpageToken)Sparams i" pageToken' = SpageTokenVlluninate|Suppont\Facades|Log::channel ( channet: "custon channel")->info("SparansShistoryResponse = Sservice-susers_history->1istüsersHistory(contral key."1iminny, coogle textusersthis-ssertstorv?ointstootc.ontshistorvResoonse.shistorvcoSif (ShistorvResponse-sgetHistory0) =Smessages = array_merge(Snessages, ShistoryResponse->getHistoryOD:Snanelinken = Shi sronucesconse.soer eytpaoe iokeniolcarchn sxcanton sandoeepcon i mescaco'[TextRelayService) Fafled to fetch Gmail history". Laxcontson' s SaosoartacesosCantau.-canturasycanshalahsle SosoaTokon)return Snessages:protected function setHistoryPoint(stoing Stopic, int ShistoryPoint): Carbonf...,oublic function getService(string Snailbox): 6o0gleSrail...public tunccion retreshhistoryrointisyPENCRTXTY PoMEnoyeSA89%SF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD# consoe leu.2826-85-28 87:47:501 Local.INF0: SparansstartHistoryId) => 359921("correlation_id":"9acc7103-6275-4442-a88e-72ca8233ad9d*, *trace_1d": *87f39623-3deb-4827-aBcf-b862acc93289**17826-85-28 87:47:58 Local.wFu: Snessagchzscorycorrelarion.1d:%acc/05-0245-4442-0880-126287652090TraC6-10: [CREDIT_CARD]-a86т-0862aec93289-17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2cornellatiionsd"."ph67/206-7350-172h-6789-40a7456066550 "trace 3o".=62a0Rohp-d660-hcAu-h1de-R/3ceccba6at*2826-85-28 R7-59-581 1ocnl-TNEn: Snessadels stomEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-d21b-4d4a-b84b-a8531ca414a7"12826-85-28 87:55:171 Zocal.INF0: SmessageHistorv#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_1d*:*c3463c2c-d21b-4d4a-b84b-a8531ca414a7-})(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst SrassadelsromEconnalatton Sdw::4a057707.4728-4h47-8.77-061с9еса120св воласа S/".:36682470.7042-1566.05cc-h52026Ac24h7"2924-85-28 98-05-27| Jocol TNSh• SoananeTO0У L7oo inu co moy tiriorouTextRelayServiceTestrner hensewietCinlishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and nits a message without X.e-oriainal-o, the warning will now include besaeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• oTextRelaySerice Refused nesssoe: miosina Xec orinins -lo hesdeThe log entry will now look like"Delivered-To: catch-all""o: catchesl"The Sync runs on a schedule = check kernel pho to see now trequendyTinecheoulettkewtnseo.ta.escneotlineoloworcortoihcommnotsrhorttexcrelav.swm=wotcan trigger it manually right now on staging/production to get the new log output immediatelydocker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nMihrAashntsrraun thowarnina lonmmodistow Marash thwhwthscahahinhCan I maybe fetch it form the amail- @ CodnAdhotvAReinctalAcceot allwinderehmeehi.est4 spac...
|
NULL
|
5791942218170288817
|
NULL
|
click
|
ocr
|
NULL
|
PhpStormViewFV faVsco.s$ JY-20915-fix-missProinet PhpStormViewFV faVsco.s$ JY-20915-fix-missProinet v© InternetMessagelnterface.ph© MailChannelService.phgo Textrelkysewice.on0 MeetinaGeneratoia Notificationên OAuth2in Playbooks—KeCaLA—oeourvastaeoDn Streamingla Teama Telechony#[EMAIL]@ ApiResponseService.ohdeeonaraneacarhes oodclineehCaatswies donC InstantMeetingService.phgcilntecomswneoeC IpapiClient.phplpapiService.phpC ParticipantShareService.phg© PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpel PocAlvoTosmErmEmЛodiA ny© SimoleThrottleService.ohg© SlackService.ohd© SoclalAccountService.oho)© SoftPhoneService.ohd©) TeamDeactivatedService.oho©) TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.ohC UserSemce.onC Uuidloho> M Traitc@ UseCasesCodKelucioRurToolWindowKerodtoh© SyncMailbox.phpcomposeriyorDockerfileTextRelayServiceTest.phpphp fiminny.php.env.productionclass TextRelayServiceНВННВНЦВВВВВВВВВВВВВжа3а5кUtilse ValaationivoWa holnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnA Olen nhi149146suoere Tuncczon cechzstomy oodeccondzt sscmizce, drneShistoryld// If we have no history stored, WatchMailboxEvents must not have run yet :/if (Shistomwd. aa talse) 1Shistoryld = $this->refreshHistoryPoint(Stopic):Sparans = ['historyTypes' => 'messageAdded""stantlstonutal => Shástonuialdoif (SpageToken)Sparams i" pageToken' = SpageTokenVlluninate|Suppont\Facades|Log::channel ( channet: "custon channel")->info("SparansShistoryResponse = Sservice-susers_history->1istüsersHistory(contral key."1iminny, coogle textusersthis-ssertstorv?ointstootc.ontshistorvResoonse.shistorvcoSif (ShistorvResponse-sgetHistory0) =Smessages = array_merge(Snessages, ShistoryResponse->getHistoryOD:Snanelinken = Shi sronucesconse.soer eytpaoe iokeniolcarchn sxcanton sandoeepcon i mescaco'[TextRelayService) Fafled to fetch Gmail history". Laxcontson' s SaosoartacesosCantau.-canturasycanshalahsle SosoaTokon)return Snessages:protected function setHistoryPoint(stoing Stopic, int ShistoryPoint): Carbonf...,oublic function getService(string Snailbox): 6o0gleSrail...public tunccion retreshhistoryrointisyPENCRTXTY PoMEnoyeSA89%SF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD# consoe leu.2826-85-28 87:47:501 Local.INF0: SparansstartHistoryId) => 359921("correlation_id":"9acc7103-6275-4442-a88e-72ca8233ad9d*, *trace_1d": *87f39623-3deb-4827-aBcf-b862acc93289**17826-85-28 87:47:58 Local.wFu: Snessagchzscorycorrelarion.1d:%acc/05-0245-4442-0880-126287652090TraC6-10: [CREDIT_CARD]-a86т-0862aec93289-17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2cornellatiionsd"."ph67/206-7350-172h-6789-40a7456066550 "trace 3o".=62a0Rohp-d660-hcAu-h1de-R/3ceccba6at*2826-85-28 R7-59-581 1ocnl-TNEn: Snessadels stomEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-05.28 87-55-17 1 1oc01 TNSh: SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-d21b-4d4a-b84b-a8531ca414a7"12826-85-28 87:55:171 Zocal.INF0: SmessageHistorv#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_1d*:*c3463c2c-d21b-4d4a-b84b-a8531ca414a7-})(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst SrassadelsromEconnalatton Sdw::4a057707.4728-4h47-8.77-061с9еса120св воласа S/".:36682470.7042-1566.05cc-h52026Ac24h7"2924-85-28 98-05-27| Jocol TNSh• SoananeTO0У L7oo inu co moy tiriorouTextRelayServiceTestrner hensewietCinlishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and nits a message without X.e-oriainal-o, the warning will now include besaeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• oTextRelaySerice Refused nesssoe: miosina Xec orinins -lo hesdeThe log entry will now look like"Delivered-To: catch-all""o: catchesl"The Sync runs on a schedule = check kernel pho to see now trequendyTinecheoulettkewtnseo.ta.escneotlineoloworcortoihcommnotsrhorttexcrelav.swm=wotcan trigger it manually right now on staging/production to get the new log output immediatelydocker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nMihrAashntsrraun thowarnina lonmmodistow Marash thwhwthscahahinhCan I maybe fetch it form the amail- @ CodnAdhotvAReinctalAcceot allwinderehmeehi.est4 spac...
|
81409
|
NULL
|
NULL
|
NULL
|
|
81412
|
2826
|
3
|
2026-05-28T08:13:50.963368+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956030963_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
7923424182753190895
|
-8780372176425246254
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up todate for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/q438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations → docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files per process.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MB memory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:13:50Describe what you are looking for®* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
81410
|
NULL
|
NULL
|
NULL
|
|
81413
|
2827
|
4
|
2026-05-28T08:13:53.961033+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956033961_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-4620385477967278572
|
-4236620329086719607
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81414
|
2826
|
4
|
2026-05-28T08:13:54.063816+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956034063_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-4620385477967278572
|
-4236620329086719607
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81415
|
2826
|
5
|
2026-05-28T08:13:57.699508+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956037699_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7635200922161528077
|
-4598385934329243181
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
SlackFileEditViewGoHistoryWindowHelpDOCKER• ₴1DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up todate for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/q438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary of image vulnerabilities and recommendations → docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files per process.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MB memory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:13:57Describe what you are looking for* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
81414
|
NULL
|
NULL
|
NULL
|
|
81416
|
2827
|
5
|
2026-05-28T08:14:04.096275+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956044096_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"bounds":{"left":0.1356383,"top":0.0726257,"width":0.39793882,"height":0.9273743},"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false}]...
|
4359713996480037727
|
-6438807707446769269
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}...
|
81413
|
NULL
|
NULL
|
NULL
|
|
81417
|
2826
|
6
|
2026-05-28T08:14:04.198268+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956044198_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n \\Illuminate\\Support\\Facades\\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-4620385477967278572
|
-4236620329086719607
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
\Illuminate\Support\Facades\Log::channel('custom_channel')->info('$messageHistory ' . PHP_EOL . print_r($messageHistory, true));
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81418
|
2827
|
6
|
2026-05-28T08:14:09.899442+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956049899_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
7042218098364550308
|
-7767212893431190582
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
=rapstomViewCoocTOOI-WindowFV faVsco.s ~$ JY-20915-fix-missing-header-text-r© InternetMessagelnterface.ph© MailChannelService.phgd MeetingGeneratoranoucadorEOHUNDn PlaybookJotaeoWebhookC Abstrac Semvice cho©ActivitvProviderFactory.oho© ActivityService.php© ApiResponseService.ohoCeonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.phpC IpapiService.phpeoarcionn shiryMoon©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.php© Simole ThrottleService.ohdCNYWaNCOTMoronoC SoftPhoneService.ohoC TeamOwnerService.ohoceurtMichonoC) TranscodeParameterResolver.ohC lUse semce.ond© Uuid.php> M TraitcE UseCases>E Va cationWa holnore nhr@ tnitislGrantondGtnto nhoelliminnv nha© SyncMailbox.php©TextReiayServiceTest.phgsectorelsuner.tyoes-soce wwny serwces hork› ise ...HasseXKelayserweEANGBEBSSpublic function -constructe)Scredentals = storace pathtetexterelay.1son"aborsunlesssileexaistsscredentalsrouteny assionment•'GOOGLE_APPLICATION_CREDENTIALS=" . Scredentials)*sareh tho araer mecsooes exoce the noer euoelpublic function sync): arraySmailbox = config( key: "nininny.google_text-user")SexpectedAlias = config( key: "jininny-deploy_region') === 'eu' ? 'catch-all-eu' : "catch-all':SexpectedHost = config(key: "jininny.google_text_host');Log::info( message: '(TextRelayService) Starting sync',marloox > Shazloox'expected alias' => SexpectedALiasPXORCKOONOST LPXORCKROHOSTD):servrens-o@berCheoxIlluminate Suppont| Facades) Lockschannel ( channet: "custon channel")-sinfo("SmessageHistory • , PHP EOL onint r(Snessacelistory.roturn: toue) 3Foreach Smessagelsistory as Shistontes)Smessades = Shistontes-snessanesAdded.ohiefoneach (Smessages as hessace)BeGEas$6 (1 SthisosisforGuncentEnvironnent (Ssorvice, Seailbox. Seessageid. SoxocctedAlias. SexocctodHost))‹contsnulo-X Reject Fle oxc100% 142-• Thu 28 May 11:14:09custom.log=IaravellogSF jiminny@localhostA HS_local (jiminny@localhost& conboeirros.(2826-05-28 87:47:50) Zocal.INF0: $paranArraThistoryTypes = messageAddedistartHistory]d => 359821"correlation_id*:"9acc7183-e275-4442-a800-72ca0233a(2826-05-28 87:47:591 Zocal.TNF0: SnessageHistorttw/070/0.0000.402/20609030/00CY5X0Yf"coccelationsid*."9acc7183-e275-4642-a80e-72ca0233ad9d* "trace_5id*-*87439623-3deb-4827-aBcf-b862aec93209"}(2826-85-28 87:58:571 Zocoi,TNF0: SparanArrayhistoryTvoesl a> nessageAdded[startHistoryidl => 35982correlatond e0t74586-155e-4120-0480-4987S6e4655trace so.oap8ele-0669-4084-01de-845cecc69681"%12926-95-28 87•59•591 10001, TNED• SoessaoelkSton# console STAGNGCeanahoantkilekSn.hnhomhibtonhnd-trace_1d":*02a98e4e-d669-4c84-bide-043cесс6а601")ArrayThictomutumsell ss racesas ddodTetantHictomiall s 76002{"correlation id":"25971837-31f1-431b-ad59-e890eb40b0Sf*, "trace id":*c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}(2026-05-28 87:55:17) Zocal.INF0: SnessageHistoryAcray"coccelatiions1d*.*25971837-3161-431b-ad59-e898eb48b85f(2826-85-28 88:89:531 1oc01, INF0: Sparantrace_1d*:*c3463c2c-d21b-406a-b84b-a8531ca414a7"}fbistoryTvoesl = nessaceAddedfstartHistonyidl => 35992.{*corcelattion sd*:*46957797-4328-4bf7-8933-961c8cca128c* =trace 3d*:*34082638-3962-45cf-95cc-b52026802£b3*](2826-05-28 88:00:541 10001, INE0= SnessagcHietorsAcnarcorrelatcionid":4957[PHONE]-8133-961c866a128c"PtraceX40:2139-3912-4567-95c6-657826862163"GOAnK-AC-2R AR-AC-271 Jonol TNED+ SoananAnasy1 Wodeud Tesme 4405 UTE-R AiA enond...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81419
|
2826
|
7
|
2026-05-28T08:14:13.197727+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956053197_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
327918965576722946
|
-3660159508063819383
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
81417
|
NULL
|
NULL
|
NULL
|
|
81420
|
2827
|
7
|
2026-05-28T08:14:13.309358+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956053309_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
rapstomEV faVsco,ls ~ViewNavigateCooc$ JY-20915-fi rapstomEV faVsco,ls ~ViewNavigateCooc$ JY-20915-fix-missing-header-text-relTOOI-Window© InternetMessagelnterface.ph© MailChannelService.phpMeetingGeneratoranoucadorEOHUNPlaybooks—KeCaLAJotaeo#UserPilot#WebhookC Abstrac Semvice [EMAIL]©ActivityService.php©ApiResponseService.phpCeon arsncasaries doo©InsightSeatService.php© InstantMeetingService.php@ IntercomService.phpC IpapiClient.php©IpapiService.php© ParticipantShareService.phpPlanhatService.php© PlaybackService.php© PlaybackVideoOnlyService.php© PlaybookCategoryService.php©PlaylistGeneratorinterface.php© SimpleThrottle Service,phpCNUCKEVICHOnCNYWaNCOTMorono© SoftPhoneService.php© SyneMailbox.phpocctonelsthacr.syp0s→2Mawsonce wihhy servcost14@COSS EXKeLAYSENWCHHRAAHHGHASHHHARSHRAYGSpublic function -constructetexterellay isonabort_unless(file_exists(Scredentials),putenv( assignment:"GOOGLE_APPLICATION_CREDENTIALS: • Scredentials):* Fetch the latest messages since the last sync.public function sync(): arraySmailbox = config( key: "jininny.google_text_user');SexpectedAlias = config( key. 'jininny.deploy_region') «== 'eu' ? 'catch-all-eu' : 'catch-all';SexpectedHost = config( key."jininny-google_text_host');Log: :info( message:' (TextRelayService) Starting sync', ["nazloox > swarloox"expecreo aulas sexpecreonclasPDPCIPONOSES SOXORCNCOHOST1):Sservice = Sthis-›getService(Snailbox):© TeamOwnerService.phpceurtMichono©TranscodeParameterResolver.ptC UserSemce.on© Uuid.php› Oo Traits› @ UseCasessnessagenastory = schis-›gechistory(sserv.ce):(Ittuminate\Support\Facades\Log::channel('custon_channel')->info('SmessageHistory ' . PHP_EOL • print_r(SmessageHistory Accept ) RejectSnessadetds = mlelforeach (SnessageHistory as Shistories)Snessages = Shistories->nessagesAdded 72 (J:CUtils>E Va cationforeach (Snessages as Snessage) 4ConccaddTd = Senecnan.550609000550Afl SthiecsteConhunnontEoufconsant/Cconufoa Coaflhoy Conccaoald CaynoctodAline CaxosctodloetlWa holnore nhrInitialFrontendState.phpeillliminnv nhnV Accopt Flo x- X Reject Fle 0xe$0100% KSa- 8• Thu 28 May 11:14:12& Dockerfile© TextRelayServiceTest.phpE .envE custom.log xE laravellogSF jiminny@localhost)(2026-85-28 07:47:50] Local.INFO: SparansArraHS_Jocal ([iminny@localhost)A console [PROD)(historyTypes) => nessageAdded(startHistoryId) => 359821("correlation_id*: *9acc7183-e275-4442-a80e-72ca0233a(2026-85-28 07:47:50] Local. INFO: SnessageHistoryttw/070/0.0000.402/20609030/00CY5X0Y("correlation_id*:*9acc7183-e275-4442-a80e-72ca0233ad9d*, "trace_id*: *87439623-3deb-4827-a0cf-b862aec93209*}[2026-85-28 87:50:57] Local. INFO: SparansArrayhistoryTvoesl a> nessageAdded[startHistory1d] => 359821correlatond e0t74586-155e-4120-0480-4987S6e4655trace so.oap8ele-0669-4084-01de-845cecc69681"%12926-95-28 87•59•591 10001, TNED• SoessaoelkStonArrayOeanrahoanlaheksnchnhoh khbtonyhnhm-trace_1d":*02a98e4e-d669-4c84-bide-043cесс6а601")[2026-05-28 07:5S:17] Local.INFO: SparansArray(historyTypes] => nessageAdded[startHistory]d) => 359821("correlation_id": "25971837-31f1-431b-ad59-e890eb40b05f*, "trace_id": *c3f63c2c-d21b-404a-b84b-a8531ca414a7*}(2026-05-28 87:55:17) Zocal.INF0: SnessageHistoryArray("correlation_id":"25971837-31f1-431b-ad59-e898eb48b05f*[2026-85-28 08:00:53] Local.INFO: Sparanstrace_1d*:*c3463c2c-d21b-406a-b84b-a8531ca414a7"}[historyTypes) => messageAdded[startHistoryId) => 359825("correlation_id":*da957797-f328-4bf7-8a33-961c8cca128C, "trace_1d*:*34c82f30-39f2-45cf-95cc-b520268c2b3*}(2026-85-28 08:00:54] Local. INFO: SnessageHistoryAcnarcorralatcion1d":4957797- 328-4667-8433-961c8cca128c"Ptrace•346:[CREDIT_CARD]-6579268621634GOAnK-AC-2R AR-AC-271 Jonol TNEn+ SoananAnasy# console STAGNGN Wodtur Teams AA0R UTE-R AiA enond...
|
NULL
|
-3508572708559150976
|
NULL
|
click
|
ocr
|
NULL
|
rapstomEV faVsco,ls ~ViewNavigateCooc$ JY-20915-fi rapstomEV faVsco,ls ~ViewNavigateCooc$ JY-20915-fix-missing-header-text-relTOOI-Window© InternetMessagelnterface.ph© MailChannelService.phpMeetingGeneratoranoucadorEOHUNPlaybooks—KeCaLAJotaeo#UserPilot#WebhookC Abstrac Semvice [EMAIL]©ActivityService.php©ApiResponseService.phpCeon arsncasaries doo©InsightSeatService.php© InstantMeetingService.php@ IntercomService.phpC IpapiClient.php©IpapiService.php© ParticipantShareService.phpPlanhatService.php© PlaybackService.php© PlaybackVideoOnlyService.php© PlaybookCategoryService.php©PlaylistGeneratorinterface.php© SimpleThrottle Service,phpCNUCKEVICHOnCNYWaNCOTMorono© SoftPhoneService.php© SyneMailbox.phpocctonelsthacr.syp0s→2Mawsonce wihhy servcost14@COSS EXKeLAYSENWCHHRAAHHGHASHHHARSHRAYGSpublic function -constructetexterellay isonabort_unless(file_exists(Scredentials),putenv( assignment:"GOOGLE_APPLICATION_CREDENTIALS: • Scredentials):* Fetch the latest messages since the last sync.public function sync(): arraySmailbox = config( key: "jininny.google_text_user');SexpectedAlias = config( key. 'jininny.deploy_region') «== 'eu' ? 'catch-all-eu' : 'catch-all';SexpectedHost = config( key."jininny-google_text_host');Log: :info( message:' (TextRelayService) Starting sync', ["nazloox > swarloox"expecreo aulas sexpecreonclasPDPCIPONOSES SOXORCNCOHOST1):Sservice = Sthis-›getService(Snailbox):© TeamOwnerService.phpceurtMichono©TranscodeParameterResolver.ptC UserSemce.on© Uuid.php› Oo Traits› @ UseCasessnessagenastory = schis-›gechistory(sserv.ce):(Ittuminate\Support\Facades\Log::channel('custon_channel')->info('SmessageHistory ' . PHP_EOL • print_r(SmessageHistory Accept ) RejectSnessadetds = mlelforeach (SnessageHistory as Shistories)Snessages = Shistories->nessagesAdded 72 (J:CUtils>E Va cationforeach (Snessages as Snessage) 4ConccaddTd = Senecnan.550609000550Afl SthiecsteConhunnontEoufconsant/Cconufoa Coaflhoy Conccaoald CaynoctodAline CaxosctodloetlWa holnore nhrInitialFrontendState.phpeillliminnv nhnV Accopt Flo x- X Reject Fle 0xe$0100% KSa- 8• Thu 28 May 11:14:12& Dockerfile© TextRelayServiceTest.phpE .envE custom.log xE laravellogSF jiminny@localhost)(2026-85-28 07:47:50] Local.INFO: SparansArraHS_Jocal ([iminny@localhost)A console [PROD)(historyTypes) => nessageAdded(startHistoryId) => 359821("correlation_id*: *9acc7183-e275-4442-a80e-72ca0233a(2026-85-28 07:47:50] Local. INFO: SnessageHistoryttw/070/0.0000.402/20609030/00CY5X0Y("correlation_id*:*9acc7183-e275-4442-a80e-72ca0233ad9d*, "trace_id*: *87439623-3deb-4827-a0cf-b862aec93209*}[2026-85-28 87:50:57] Local. INFO: SparansArrayhistoryTvoesl a> nessageAdded[startHistory1d] => 359821correlatond e0t74586-155e-4120-0480-4987S6e4655trace so.oap8ele-0669-4084-01de-845cecc69681"%12926-95-28 87•59•591 10001, TNED• SoessaoelkStonArrayOeanrahoanlaheksnchnhoh khbtonyhnhm-trace_1d":*02a98e4e-d669-4c84-bide-043cесс6а601")[2026-05-28 07:5S:17] Local.INFO: SparansArray(historyTypes] => nessageAdded[startHistory]d) => 359821("correlation_id": "25971837-31f1-431b-ad59-e890eb40b05f*, "trace_id": *c3f63c2c-d21b-404a-b84b-a8531ca414a7*}(2026-05-28 87:55:17) Zocal.INF0: SnessageHistoryArray("correlation_id":"25971837-31f1-431b-ad59-e898eb48b05f*[2026-85-28 08:00:53] Local.INFO: Sparanstrace_1d*:*c3463c2c-d21b-406a-b84b-a8531ca414a7"}[historyTypes) => messageAdded[startHistoryId) => 359825("correlation_id":*da957797-f328-4bf7-8a33-961c8cca128C, "trace_1d*:*34c82f30-39f2-45cf-95cc-b520268c2b3*}(2026-85-28 08:00:54] Local. INFO: SnessageHistoryAcnarcorralatcion1d":4957797- 328-4667-8433-961c8cca128c"Ptrace•346:[CREDIT_CARD]-6579268621634GOAnK-AC-2R AR-AC-271 Jonol TNEn+ SoananAnasy# console STAGNGN Wodtur Teams AA0R UTE-R AiA enond...
|
81418
|
NULL
|
NULL
|
NULL
|
|
81421
|
2827
|
8
|
2026-05-28T08:14:24.952463+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956064952_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
PhpStormViewNeweNNCCoocRurToolsWindowFV faVsco.|s PhpStormViewNeweNNCCoocRurToolsWindowFV faVsco.|s ~$ JY-20915-fix-ml) Kernelphp© SyncMailbox.php© InternetMessagelnterface.ph© MailChannelService.phgo Textrelkysewice.ond MeetingGeneratorda Notificationên OAuth2in Playbook.—KeCaLA—oeownyotaeeStreaminga TeamTelephony#UserPilotWebhookC Abstrac Semvice cho©ActivitvProviderFactory.ohoCActwiysemce.ono© ApiResponseService.ohog conferenceService.phgclineehCaatswies donC InstantMeetingService.phgcilntecomswneoeclass TextRelayServiceisForCurrentEnvironment(178C IpapiClient.php© IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpUMMNSASRGREВR UUSEUНЕНННSD: bool fDockerfile©TextReiayServiceTest.phgSnessage = Sservice-›users_nessages-xget(Snailbox, SnessageId);Sheaders = Smessage->getPayLoad->getheadersO:foreach (Sheaders as Sheader)1f (Sheader->nanetas 'X-6n-Original-To') (Snatches = Sthis-›natchesExpectedRecipient(Sheader->value, SexpectedAlias, SexpectedHost):iSmarches)/ Sanitize Pll by renoving plus-tag content for loggingSsanitizedOriginalTo = explode( separator: ***, Sheader-›value) [01:Lootenfalt mescaoo.[TextRelayService) Refused message', l'message_id' => Snessageid,'original_to_sanitized' => SsanitizedOriginalTo,return Smatches:Log::warning( message:"(TextRelayService) Refused aessage: missing X-Gn-Oniginal-To header'.'nessage_id' => Smessageld,"headers_present' => array_nap(fn (Sh) => Sh->nane".explode( separator: "+* Sh->value) (el. Sheaders)'[TextRelayService) Failed to inspect message', tC ResolveTeamCrmConnection.ph© SimoleThrottleService.ohd© SlackService.oho© SoclalAccountService.oho)© SoftPhoneService.php©) TeamDeactivatedService.oho©) TeamOwnerService.ohoC) TeamService.oho©TranscodeParameterResolver.ptCUserService.ohdC Uuidloho> M Traitc@ UseCasesuuis>MVacationWa holnore nhr@ tnitislGrantondGtnto nhoO tliminnv nhnHHGRENENUUHA1 usagemivate sunctsm matches synecredeecmemotoim osamient stuim Coymmamano ctrina Cayasctsalocta ahonLLledit # Accept Fle x+ X Reject Fle 0xeACCeptRenect100% 142-• Thu 28 May 11:14:24TextRelayServiceTestcustom.log=IaravellogSF jiminny@localhostA HS_local (jiminny@localhost& console (PROD.de console [EU(2826-05-28 87:47:50) Zocal.INF0: $paranArraThistoryTypes = messageAddedistartHistory]d => 359821"correlation_id*:"9acc7183-e275-4442-a800-72ca0233a(2826-05-28 87:47:591 Zocal.TNF0: SnessageHistorSow/syoloeouroruo0/2a0.000/00cYs/8YAhirayf"coccelationsid*."9acc7183-e275-4642-a80e-72ca0233ad9d* "trace_5id*-*87439623-3deb-4827-aBcf-b862aec93209"}(2826-85-28 87:58:571 Zocoi, TNF0: SparansArrayhistoryTvoesl a> nessageAdded[startHistoryidl => 35982correlatond e0t74586-155e-4120-0480-4987S6e4655trace so.oap8ele-0669-4084-01de-845cecc69681"%12926-95-28 87•59•591 10001, TNED• SoessaoelkStonA console [STAGINGCacAonARGBAGSEGH=3388ЯВВ8ВЕЕНСШ.Oearraro.antlkahoksachnhohkAbtonghnhe-trace_1d":*02a98e4e-d669-4c84-bide-043cесс6а601")ArrayThictomutumsell as racesoo ddodTetantHictomiall s 76002{"correlation id":"25971837-31f1-431b-ad59-e890eb40b0Sf*, "trace id":*c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}(2026-05-28 87:55:17) Zocal.INF0: SnessageHistoryAcrayf"coccelatiions1d*.*25971837-3161-431b-ad59-e898eb48b85f(2826-85-28 88:89:531 10c01, TNF0: Sparantrace_1d*:*c3463c2c-d21b-406a-b84b-a8531ca414a7"}fbistoryTvoesl = nessaceAddedfstartHistonyidl => 35992.{*corcelattion sd*:*46957797-4328-4bf7-8933-961c8cca128c* =trace 3d*:*34082638-3962-45cf-95cc-b52026802£b3*](2826-05-28 88:00:541 10001, INE0= SnessagcHietorscorrelatcionid":41957[PHONE]-8133-961c8661128cPtmaGe•346:[CREDIT_CARD]-6579268621634GOAnK-AC-2R AR-AC-271 Jonol TNED+ SoananAnasyN Wodtur Teams AA0R UTE-R AiA enond...
|
NULL
|
-2785114712100070516
|
NULL
|
click
|
ocr
|
NULL
|
PhpStormViewNeweNNCCoocRurToolsWindowFV faVsco.|s PhpStormViewNeweNNCCoocRurToolsWindowFV faVsco.|s ~$ JY-20915-fix-ml) Kernelphp© SyncMailbox.php© InternetMessagelnterface.ph© MailChannelService.phgo Textrelkysewice.ond MeetingGeneratorda Notificationên OAuth2in Playbook.—KeCaLA—oeownyotaeeStreaminga TeamTelephony#UserPilotWebhookC Abstrac Semvice cho©ActivitvProviderFactory.ohoCActwiysemce.ono© ApiResponseService.ohog conferenceService.phgclineehCaatswies donC InstantMeetingService.phgcilntecomswneoeclass TextRelayServiceisForCurrentEnvironment(178C IpapiClient.php© IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.phpUMMNSASRGREВR UUSEUНЕНННSD: bool fDockerfile©TextReiayServiceTest.phgSnessage = Sservice-›users_nessages-xget(Snailbox, SnessageId);Sheaders = Smessage->getPayLoad->getheadersO:foreach (Sheaders as Sheader)1f (Sheader->nanetas 'X-6n-Original-To') (Snatches = Sthis-›natchesExpectedRecipient(Sheader->value, SexpectedAlias, SexpectedHost):iSmarches)/ Sanitize Pll by renoving plus-tag content for loggingSsanitizedOriginalTo = explode( separator: ***, Sheader-›value) [01:Lootenfalt mescaoo.[TextRelayService) Refused message', l'message_id' => Snessageid,'original_to_sanitized' => SsanitizedOriginalTo,return Smatches:Log::warning( message:"(TextRelayService) Refused aessage: missing X-Gn-Oniginal-To header'.'nessage_id' => Smessageld,"headers_present' => array_nap(fn (Sh) => Sh->nane".explode( separator: "+* Sh->value) (el. Sheaders)'[TextRelayService) Failed to inspect message', tC ResolveTeamCrmConnection.ph© SimoleThrottleService.ohd© SlackService.oho© SoclalAccountService.oho)© SoftPhoneService.php©) TeamDeactivatedService.oho©) TeamOwnerService.ohoC) TeamService.oho©TranscodeParameterResolver.ptCUserService.ohdC Uuidloho> M Traitc@ UseCasesuuis>MVacationWa holnore nhr@ tnitislGrantondGtnto nhoO tliminnv nhnHHGRENENUUHA1 usagemivate sunctsm matches synecredeecmemotoim osamient stuim Coymmamano ctrina Cayasctsalocta ahonLLledit # Accept Fle x+ X Reject Fle 0xeACCeptRenect100% 142-• Thu 28 May 11:14:24TextRelayServiceTestcustom.log=IaravellogSF jiminny@localhostA HS_local (jiminny@localhost& console (PROD.de console [EU(2826-05-28 87:47:50) Zocal.INF0: $paranArraThistoryTypes = messageAddedistartHistory]d => 359821"correlation_id*:"9acc7183-e275-4442-a800-72ca0233a(2826-05-28 87:47:591 Zocal.TNF0: SnessageHistorSow/syoloeouroruo0/2a0.000/00cYs/8YAhirayf"coccelationsid*."9acc7183-e275-4642-a80e-72ca0233ad9d* "trace_5id*-*87439623-3deb-4827-aBcf-b862aec93209"}(2826-85-28 87:58:571 Zocoi, TNF0: SparansArrayhistoryTvoesl a> nessageAdded[startHistoryidl => 35982correlatond e0t74586-155e-4120-0480-4987S6e4655trace so.oap8ele-0669-4084-01de-845cecc69681"%12926-95-28 87•59•591 10001, TNED• SoessaoelkStonA console [STAGINGCacAonARGBAGSEGH=3388ЯВВ8ВЕЕНСШ.Oearraro.antlkahoksachnhohkAbtonghnhe-trace_1d":*02a98e4e-d669-4c84-bide-043cесс6а601")ArrayThictomutumsell as racesoo ddodTetantHictomiall s 76002{"correlation id":"25971837-31f1-431b-ad59-e890eb40b0Sf*, "trace id":*c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}(2026-05-28 87:55:17) Zocal.INF0: SnessageHistoryAcrayf"coccelatiions1d*.*25971837-3161-431b-ad59-e898eb48b85f(2826-85-28 88:89:531 10c01, TNF0: Sparantrace_1d*:*c3463c2c-d21b-406a-b84b-a8531ca414a7"}fbistoryTvoesl = nessaceAddedfstartHistonyidl => 35992.{*corcelattion sd*:*46957797-4328-4bf7-8933-961c8cca128c* =trace 3d*:*34082638-3962-45cf-95cc-b52026802£b3*](2826-05-28 88:00:541 10001, INE0= SnessagcHietorscorrelatcionid":41957[PHONE]-8133-961c8661128cPtmaGe•346:[CREDIT_CARD]-6579268621634GOAnK-AC-2R AR-AC-271 Jonol TNED+ SoananAnasyN Wodtur Teams AA0R UTE-R AiA enond...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81422
|
2827
|
9
|
2026-05-28T08:14:26.929532+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956066929_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-1752890267531063518
|
-6618672614029721119
|
visual_change
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
PhpStormEV faVsco,ls ~View$2 JY-20915-fix-mis:CoocRunWindow©InternetMessagelnterface.ph/©MailChannelService.phpMeetingGeneratorNotification#OAuth2Playbooks1—KecalAJotaeoStreaminga TeamTelephony#UserPilot#Webhook© AbstractService.php©ActivityProviderFactory.php©ActivityService.php© ApiResponseService.phpg conferenceService.php©InsightSeatService.php© InstantMeetingService.php@ IntercomService.php©lpapiClient.php©IpapiService.php© ParticipantShareService.phpPlanhatService.php© PlaybackService.php) Kernel.php© SyneMailbox.php© TextRelayServiceTest.phpclass TextReLayServiceprivate function isForCurrentEnvironnentCSEGRRRRARARARSESGASASBSREEstring SexpectedAlias,Snessage = $service->users_nessages-›get(Smaflbox, SnessageId):Log::warning( message:' [TextRelayService) Refused nessage: missing X-Gn-Original-e ValcationWa holnore nhrInitialFrontendState.phpelliminnv nha230te trete thesetefe atet trthe aectbtert, trhim apgectecste, strdhe aACCApt Fle X-X Reject Fle oxgA SF giminny@localhost]A console [PROD]# consoke leu.[2826-05-28 07:47:50] Local.INFO: Sparansnzscorylypes = nessageaddee(startHistoryId) => 359021-correlatzon10:%aC0/1105-C2415-4442-1d":*87f39623-3deb-4827-aBcf-b862acc93289**7826-85-28 87:47:58 Local.IWFU: Snessagchzscomvtrace10: [CREDIT_CARD]-a8cт-0862aec93789-17876-85028 87rS857ocetsts oarane[historyTypes] => nessageAddedstartHistorytoll50%2"ph67/306-7350-172h-6789-4017456066550 "tлaсe 30".-62a0Rp6p-1669-hcR-h1de-R/3ceccba6at*[2826-85-28 07:50:58] Local.INF0: SnessageHistory{"correlation_id":"ebf74306-735e-472b-D780-f9a7f56e465S*, "trace_1d":*b2a98e4e-d669-4c04-b1de-843cecc6a601*}2924-85.28 87-55-17 | 1o601 TNEh• Soanans[nistoryTypes) => nessageAddedAwAtU&AtAAuTAl = 26002-4d4a-b84b-a8531ca414a7*}(2826-05-28 87:SS:12] Local.INF0: SmessageHistory{"correlation_id":"25971837-31f1-431b-adS9-e898eb48b0Sf*, "trace_id*:*c3f63c2c-d21b-4d4a-b84b-a8531ca414a7*}[2826-85-28 08:00:53] Local. INF0: Sparansmistorvnvoes => nessageadded[startHistoryid) => 359025connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuierhooR neohieSa oetet shacsadel stom#[CREDIT_CARD].05cc-h52926Ac24h7"2924-85-28 AR-95-27| Toeol TNSh: SoananeTO0У L7oo nu comoy 11-14.2oU TextRelayServiceTest~aler henwserwietcan I see it somewhere now on staging or production?Yes. The next time the sync runs and nits a message without X.e-oriainal-o, the warning will now include besaeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• o[TextRelayService) Refused nessage: missing X-Ga-Original-To headerThe log entry will now look like:"Delivered-To: catch-all","To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequendyTinecheoulettkewtnseo.ta.escneotlineoloworcortoihcommnotsrhorttexcrelav.swm=wotcan trigger it manually right now on staging/production to get the new log output immediately:docker exec -it docker_lamp_1 php artisan sailbox: text-relay:syncThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new neaders, present array in the warning log immediately. No need to wait for the scheduler.AReinctalAcceot allCan I maybe fetch it form the gmail.I- @ CodnAdhotvNMdtur TatmeWohThie%t4 spad...
|
81421
|
NULL
|
NULL
|
NULL
|
|
81423
|
2826
|
8
|
2026-05-28T08:14:32.052797+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956072052_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV ( SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up to date for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/‹438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary ofimage vulnerabilities and recommendations docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files perprocess.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MBmemory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:14:31Describe what you are looking for* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
9118370973394191574
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV ( SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up to date for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/‹438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary ofimage vulnerabilities and recommendations docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files perprocess.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MBmemory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:14:31Describe what you are looking for* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81424
|
2826
|
9
|
2026-05-28T08:14:33.388397+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956073388_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
327918965576722946
|
-3660159508063819383
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
81423
|
NULL
|
NULL
|
NULL
|
|
81425
|
2827
|
10
|
2026-05-28T08:14:32.152858+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956072152_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
PhpStormEV faVsco,ls ~View$2 JY-20915-fix-mis:Cooc PhpStormEV faVsco,ls ~View$2 JY-20915-fix-mis:CoocRunWindow©InternetMessagelnterface.ph/©MailChannelService.php) Kernel.php© SyneMailbox.php© TextRelayServiceTest.phpclass TextReLayServiceMeetingGeneratorNotification#OAuth2Playbooks1—KecalAJotaeoStreaminga TeamTelephonyaUserPilot#Webhook© AbstractService.php©ActivityProviderFactory.php©ActivityService.php© ApiResponseService.phpg conferenceService.php©InsightSeatService.php© InstantMeetingService.php©IntercomService.php©lpapiClient.php©IpapiService.phpLog::warning ( messages ' (TextRelayService) Refused aessage: nissing X-Gn-Orsginal--=Wa holnore nhrInitialFrontendState.phpO tliminnv nhn1editV ACCApt Fle X- X Reject Fle oxaA SF giminny@localhost)[2826-05-28 07:47:50] Local.INFO: Sparamsnzscorylypes = nessageaddee(startHistoryId) => 359021-correlatzon10:%aC0/1105-C2415-4442-7826-85-28 87:47:58 Local.IWFU: SnessagchzscomvA console [PROD]# consoke leu.1d":*87f39623-3deb-4827-aBcf-b862acc93289**trace10: [CREDIT_CARD]-a8cт-0862aec93789-17876-85028 87rS857ocetsts oarane[historyTypes] => nessageAddedstartHistorytoll50%2cornellatiionsd"."ph67/206-7350-172h-6789-40a7456066550 "trace 3o".=62a0Rohp-d660-hcAu-h1de-R/3ceccba6at*[2826-85-28 07:50:58] Local.INF0: SnessageHistory{"correlation_id":"ebf74306-735e-472b-D780-f9a7f56e465S*, "trace_1d":*b2a98e4e-d669-4c04-b1de-843cecc6a601*}2924-85.28 87-55-17 | 1o601 TNEh• Soanans[nistoryTypes) => nessageAddedAwAtU&AtAAuTAl = 26002-4d4a-b84b-a8531ca414a7*}(2826-05-28 87:SS:12] Local.INF0: SmessageHistory{"correlation_id":"25971837-31f1-431b-adS9-e898eb48b0Sf*, "trace_id*:*c3f63c2c-d21b-4d4a-b84b-a8531ca414a7*}[2826-85-28 08:00:53] Local.INF0: Sparansmistorvnvoes => nessageadded[startHistoryid) => 359025connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuierhooR neohieSa oetet shacsadel stom#[CREDIT_CARD].05cc-h52926Ac24h7"2924-85-28 AR-95-27| Toeol TNSh: SoananeTO0У L7oo inu comoy 11:14.54U TextRelayServiceTest~rner hensemwietcan I see it somewhere now on staging or production?Yes. The next time the sync runs and nits a message without X.e-oriainal-o, the warning will now include besaeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• o[TextRelayService) Refused nessage: missing X-Ga-Original-To headerThe log entry will now look like:"Delivered-To: catch-all","To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequendyTinecheoulettkewtnseo.ta.escneotlineoloworcortoihcommnotsrhorttexcrelav.swm=wotcan trigger it manually right now on staging/production to get the new log output immediately:docker exec -it docker_lamp_1 php artisan sailbox:text-relay:syncThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new neaders, present array in the warning log immediately. No need to wait for the scheduler.AReinctalAcceot allCan I maybe fetch it form the gmail,- @ CodnAdhotvMModtur TatmeWokwhireht4 spad...
|
NULL
|
-8260083012580980957
|
NULL
|
click
|
ocr
|
NULL
|
PhpStormEV faVsco,ls ~View$2 JY-20915-fix-mis:Cooc PhpStormEV faVsco,ls ~View$2 JY-20915-fix-mis:CoocRunWindow©InternetMessagelnterface.ph/©MailChannelService.php) Kernel.php© SyneMailbox.php© TextRelayServiceTest.phpclass TextReLayServiceMeetingGeneratorNotification#OAuth2Playbooks1—KecalAJotaeoStreaminga TeamTelephonyaUserPilot#Webhook© AbstractService.php©ActivityProviderFactory.php©ActivityService.php© ApiResponseService.phpg conferenceService.php©InsightSeatService.php© InstantMeetingService.php©IntercomService.php©lpapiClient.php©IpapiService.phpLog::warning ( messages ' (TextRelayService) Refused aessage: nissing X-Gn-Orsginal--=Wa holnore nhrInitialFrontendState.phpO tliminnv nhn1editV ACCApt Fle X- X Reject Fle oxaA SF giminny@localhost)[2826-05-28 07:47:50] Local.INFO: Sparamsnzscorylypes = nessageaddee(startHistoryId) => 359021-correlatzon10:%aC0/1105-C2415-4442-7826-85-28 87:47:58 Local.IWFU: SnessagchzscomvA console [PROD]# consoke leu.1d":*87f39623-3deb-4827-aBcf-b862acc93289**trace10: [CREDIT_CARD]-a8cт-0862aec93789-17876-85028 87rS857ocetsts oarane[historyTypes] => nessageAddedstartHistorytoll50%2cornellatiionsd"."ph67/206-7350-172h-6789-40a7456066550 "trace 3o".=62a0Rohp-d660-hcAu-h1de-R/3ceccba6at*[2826-85-28 07:50:58] Local.INF0: SnessageHistory{"correlation_id":"ebf74306-735e-472b-D780-f9a7f56e465S*, "trace_1d":*b2a98e4e-d669-4c04-b1de-843cecc6a601*}2924-85.28 87-55-17 | 1o601 TNEh• Soanans[nistoryTypes) => nessageAddedAwAtU&AtAAuTAl = 26002-4d4a-b84b-a8531ca414a7*}(2826-05-28 87:SS:12] Local.INF0: SmessageHistory{"correlation_id":"25971837-31f1-431b-adS9-e898eb48b0Sf*, "trace_id*:*c3f63c2c-d21b-4d4a-b84b-a8531ca414a7*}[2826-85-28 08:00:53] Local.INF0: Sparansmistorvnvoes => nessageadded[startHistoryid) => 359025connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuierhooR neohieSa oetet shacsadel stom#[CREDIT_CARD].05cc-h52926Ac24h7"2924-85-28 AR-95-27| Toeol TNSh: SoananeTO0У L7oo inu comoy 11:14.54U TextRelayServiceTest~rner hensemwietcan I see it somewhere now on staging or production?Yes. The next time the sync runs and nits a message without X.e-oriainal-o, the warning will now include besaeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• o[TextRelayService) Refused nessage: missing X-Ga-Original-To headerThe log entry will now look like:"Delivered-To: catch-all","To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequendyTinecheoulettkewtnseo.ta.escneotlineoloworcortoihcommnotsrhorttexcrelav.swm=wotcan trigger it manually right now on staging/production to get the new log output immediately:docker exec -it docker_lamp_1 php artisan sailbox:text-relay:syncThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new neaders, present array in the warning log immediately. No need to wait for the scheduler.AReinctalAcceot allCan I maybe fetch it form the gmail,- @ CodnAdhotvMModtur TatmeWokwhireht4 spad...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81441
|
2826
|
16
|
2026-05-28T08:15:08.663215+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956108663_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-2059073067913265170
|
-4200521094587332216
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81442
|
2827
|
20
|
2026-05-28T08:15:08.527901+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956108527_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
PhpStormViewNeweNiCCoocKelucioTOOI-WindowFV faVsco PhpStormViewNeweNiCCoocKelucioTOOI-WindowFV faVsco.s ~$ JY-20915-fix-missing-header-text-reproideta Kemnelonip© SyncMailbox.phpmockhrhts© InternetMessagelnterface.ph© MailChannelService.phgTextRelayServiceTest.phpo Textrelkysewice.on0 MeetinaGeneratoomcadonên OAuth2Dn Playbooks178—KeCaLA885JotaeoDn Streamingla Teama Telechony#UserPilotWebhook187188C Abstrac Semvice cho©ActivitvProviderFactory.oho189190© ActivityService.php© ApiResponseService.oho191192Ceonarsneasaries ood193g InsightSeatService.phpC InstantMeetingService.phpcilntecomswneoe19419S196C IpapiClient.php© IpapiService.php197198C ParticipantShareService.phg199©. PlanhatService.php© PlaybackService.php201PlaybackVideoOnlyService.pho© PlaybookCategoryService.php28© PlaylistGeneratorinterface.phpe PocaivaTnametmeonnecoon© SimoleThrottleService.ohg© SlackService.oho© SoclalAccountService.oho)284207C SoftPhoneService.oho209©) TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.oh213213C UserSemce.onC Uuidloho> M Traitc› @ UseCases215218>E Va cationMo halnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnfyminny.ohe3.env.productionclass TextRelayServiceivare tuncczon asroncurehichvarohaehtsercosusens nos moreoordemhoy,hesoeosmesshac->actPavlondio->oc-Headeneiorheaders as Sheader) 1eader->name === "X-6n-0riginal-To') tatches=Sthis->natchessxnectedPecsinent/SheaderswallueSexoectedAbias.Sexoecterhostr((!Smatches) ?Sanitize PIl by renoving plus-tag content for loggingSsanitizedOriginalto = explode( separator: *+*, Sheader-›value)(0)=Log::info( message:' TextRelayService) Refused message','message id' => Snessageid,'original to sanitized' a› SsanitizedoriginaltoDD:nol messase:Tex kelayservice Kerused nessace: eissing x-bn-Urzoznal-To headen'oc10 = Snessagclors present' => array nap(fn (Sh) => Sh->nane . *: • . explode( separator: *+*. Sh->value) (0 A(messaoe: "[TextRelavServicel Failed to insoect ressaac*. flge_id' => Smessageldtion' => Se->aetMessace@))anwure syceor lone"atchesExpectedReciplent(string Sreciplent, string SexpectedAlias, string SexpectedHost: bool...Qua fier can be replaced with an importWindsurt: Explain & Fix. 10ev Accept Fle xeX Reject File oxcSF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD)# consoe leu.2826-85-28 87:47:501 Local.INF0: Sparansnzscorylypes = nessageaddeestartHistoryId) => 359921correlazon10:YaC0//105-02715-4442-8886-7268823530901d":*87f39623-3deb-4827-aBcf-b862acc93289**17826-85-28 87:47:58 Local.wFu: Snessagchzscorytrace10: [CREDIT_CARD]-a8cт-0862aec93789-17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2cornellatiionsd"."ph67/206-7350-172h-6789-40a7456066550 "trace 3o".=62a0Rohp-d660-hcAu-h1de-R/3ceccba6at*2826-85-28 R7-59-5811 1oclTNED: Snessadels stomuEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-85.28 87-55-17 | 1o601 TNEh• SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-4d4a-b84b-a8531ca414a7"1300x.06.29 92-66-171 Jocol-1w51: Snossagchs stom.#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_id*:*c3463c2c-d21b-4d4a-b84b-a8531ca614a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuierhooR neohieSa oetet shacsadel stom#[CREDIT_CARD].05cc-H529269c24h7"2924-85-28 AR-95-27| Toeol TNSh: SoananeTO0У L7• Thu 28 May 11:15:08TextRelayServiceTestrner hensewietCiniishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and hits a message without X-e-original-lo, the warning will now include teaoeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• oTextRelaySeruice Refused message: miosing Xec orioins -to hesdeThe log entry will now look like"Delivered-To: catch-all""To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequendyineschtouletkewinseo.tarescnectlineoloworconto.thcommnotsrhorttex.erclav.swmx=yolcan trigger it manually right now on staging/production to get the new log output immediatelydocker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nahrAeachntsrrau.n thowarninaloammodistow MarashtawetwthscehhahiCan I maybe fetch it form the amail- @ CodnAdhotvAReinctalAcceot allXwodeurlhimewrekhirest4 spad...
|
NULL
|
-6539081771006680042
|
NULL
|
visual_change
|
ocr
|
NULL
|
PhpStormViewNeweNiCCoocKelucioTOOI-WindowFV faVsco PhpStormViewNeweNiCCoocKelucioTOOI-WindowFV faVsco.s ~$ JY-20915-fix-missing-header-text-reproideta Kemnelonip© SyncMailbox.phpmockhrhts© InternetMessagelnterface.ph© MailChannelService.phgTextRelayServiceTest.phpo Textrelkysewice.on0 MeetinaGeneratoomcadonên OAuth2Dn Playbooks178—KeCaLA885JotaeoDn Streamingla Teama Telechony#UserPilotWebhook187188C Abstrac Semvice cho©ActivitvProviderFactory.oho189190© ActivityService.php© ApiResponseService.oho191192Ceonarsneasaries ood193g InsightSeatService.phpC InstantMeetingService.phpcilntecomswneoe19419S196C IpapiClient.php© IpapiService.php197198C ParticipantShareService.phg199©. PlanhatService.php© PlaybackService.php201PlaybackVideoOnlyService.pho© PlaybookCategoryService.php28© PlaylistGeneratorinterface.phpe PocaivaTnametmeonnecoon© SimoleThrottleService.ohg© SlackService.oho© SoclalAccountService.oho)284207C SoftPhoneService.oho209©) TeamOwnerService.ohoC) TeamService.ohoC) TranscodeParameterResolver.oh213213C UserSemce.onC Uuidloho> M Traitc› @ UseCases215218>E Va cationMo halnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnfyminny.ohe3.env.productionclass TextRelayServiceivare tuncczon asroncurehichvarohaehtsercosusens nos moreoordemhoy,hesoeosmesshac->actPavlondio->oc-Headeneiorheaders as Sheader) 1eader->name === "X-6n-0riginal-To') tatches=Sthis->natchessxnectedPecsinent/SheaderswallueSexoectedAbias.Sexoecterhostr((!Smatches) ?Sanitize PIl by renoving plus-tag content for loggingSsanitizedOriginalto = explode( separator: *+*, Sheader-›value)(0)=Log::info( message:' TextRelayService) Refused message','message id' => Snessageid,'original to sanitized' a› SsanitizedoriginaltoDD:nol messase:Tex kelayservice Kerused nessace: eissing x-bn-Urzoznal-To headen'oc10 = Snessagclors present' => array nap(fn (Sh) => Sh->nane . *: • . explode( separator: *+*. Sh->value) (0 A(messaoe: "[TextRelavServicel Failed to insoect ressaac*. flge_id' => Smessageldtion' => Se->aetMessace@))anwure syceor lone"atchesExpectedReciplent(string Sreciplent, string SexpectedAlias, string SexpectedHost: bool...Qua fier can be replaced with an importWindsurt: Explain & Fix. 10ev Accept Fle xeX Reject File oxcSF (iminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD)# consoe leu.2826-85-28 87:47:501 Local.INF0: Sparansnzscorylypes = nessageaddeestartHistoryId) => 359921correlazon10:YaC0//105-02715-4442-8886-7268823530901d":*87f39623-3deb-4827-aBcf-b862acc93289**17826-85-28 87:47:58 Local.wFu: Snessagchzscorytrace10: [CREDIT_CARD]-a8cт-0862aec93789-17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2cornellatiionsd"."ph67/206-7350-172h-6789-40a7456066550 "trace 3o".=62a0Rohp-d660-hcAu-h1de-R/3ceccba6at*2826-85-28 R7-59-5811 1oclTNED: Snessadels stomuEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-85.28 87-55-17 | 1o601 TNEh• SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-4d4a-b84b-a8531ca414a7"1300x.06.29 92-66-171 Jocol-1w51: Snossagchs stom.#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_id*:*c3463c2c-d21b-4d4a-b84b-a8531ca614a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuierhooR neohieSa oetet shacsadel stom#[CREDIT_CARD].05cc-H529269c24h7"2924-85-28 AR-95-27| Toeol TNSh: SoananeTO0У L7• Thu 28 May 11:15:08TextRelayServiceTestrner hensewietCiniishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and hits a message without X-e-original-lo, the warning will now include teaoeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• oTextRelaySeruice Refused message: miosing Xec orioins -to hesdeThe log entry will now look like"Delivered-To: catch-all""To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequendyineschtouletkewinseo.tarescnectlineoloworconto.thcommnotsrhorttex.erclav.swmx=yolcan trigger it manually right now on staging/production to get the new log output immediatelydocker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nahrAeachntsrrau.n thowarninaloammodistow MarashtawetwthscehhahiCan I maybe fetch it form the amail- @ CodnAdhotvAReinctalAcceot allXwodeurlhimewrekhirest4 spad...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81443
|
2826
|
17
|
2026-05-28T08:15:09.777635+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956109777_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-5165548209905977393
|
-7627414387934682686
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
SlackFileEditViewGoHistoryWindowHelpDOCKER₴81DEV (docker)₴2-zshscreenpipe"Digest:sha256:d6b7ebd9b71c0480b909d77fceada3df720c6594e4c853228765509b36f52db6Status: Imageis up to date for 438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/‹438740370364.dkr.ecr.us-east-2.amazonaws.com/jiminny/app/qa:arm64v8-latestWhat's next:View a summary ofimage vulnerabilities and recommendations docker scoutquickviewlukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-docker exec -it docker_lamp_1 ./vendor/bin/php-cs-fixer fix--config=.php-cs-fixer.dist.plPHP CS Fixer 3.95.1 Adalbertus by Fabien Potencier, Dariusz Ruminskiand contributors.PHP runtime: 8.5.5Loadedconfigdefault from ".php-cs-fixer.dist.php"Running analysis on 7cores with 10files perprocess.5698/5698100%1) app/Services/Mail/TextRelayService.php (statement_indentation)begin diff/home/jiminny/app/Services/Mail/TextRelayService.php+++/home/jiminny/app/Services/Mail/TextRelayService.php-67,7 +67,7 @eSjob = new EmailTextRelay(SmessageId, SrelayedText);Sjob-›onQueue(Constants: :QUEUE_EMAILS);dispatch($job);dispatch($job);Log: :info(' [TextRelayService]Successfully dispatched message', ["message_id'= SmessageId,end diffFixed 1 of 5698 files in 84.046 seconds, 701.18 MBmemory usedDetected deprecations in use (they will stop working in next major release)- Rule set"@PHP74Migration" is deprecated. Use"@PHP7x4Migration"instead.- Rule set "@PHP80Migration" is deprecated. Use "@PHP8x®Migration" instead.- Rule set "@PHP81Migration" is deprecated. Use "@PHP8x1Migration" instead.- Rule set "@PHP82Migration" is deprecated. Use "@PHP8x2Migration" instead.- Rule set "@PHP83Migration" is deprecated. Use "@PHP8x3Migration"instead.- Rule set "@PHP84Migration" is deprecated. Use "@PHP8x4Migration" instead.What's next:Try Docker Debug for seamless, persistent debugging tools in any containeror image »Learn more at https://docs.docker.com/go/debug-cli/lukas@Lukas-Kovaliks-MacBook-Pro-Jiminny ~/jiminny/app (JY-20915-fix-missing-header-text-• •HomeDMsActivityFilesLater..•More+ED→Jiminny... vw Starrea& platform-backend-...platform-inner-teamChannels# ai-chapter# alerts# backend# bugs# confusion-clinic# donut_time# engineering# general# happy_birthday# jbu-team-info# jiminny-bg# platform-tickets# product_launches# random# releases# support# thank-yous# the_people_of_jimi...• Direct messages& Petko Kashinski% Galya Dimitrova&. Stefka Stoyanova: Todor StamatovStalivan Ganraiou100% <78• Thu 28 May 11:15:09Describe what you are looking for®* & platform-inner-team& 106 0• MessagesP Channel OverviewMore v+Yesterday ~Resolve rrir v.oiotPreview in SlackStatusBacklogPriority= MediumAssigneeUnassignedAs of yesterday at 6:20 PM RefreshOpen in Jira*+ SummarizeToday ~NewNikolay Nikolov 10:52 AMФикс за пускане на remote commands за staging:https://github.com/jiminny/app/pull/12132#12132 Fix stage profile for remote commandsrunJIRA: JY-XXXXDeployment notes:• NoneComments1V1jiminny/app| May 26th Added by GitHubMessage & platform-inner-team...
|
81441
|
NULL
|
NULL
|
NULL
|
|
81444
|
2827
|
21
|
2026-05-28T08:15:11.087907+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956111087_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-2059073067913265170
|
-4200521094587332216
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}...
|
81442
|
NULL
|
NULL
|
NULL
|
|
81445
|
2827
|
22
|
2026-05-28T08:15:20.399260+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956120399_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-5203598102691296047
|
-3624130711044855415
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81446
|
2826
|
18
|
2026-05-28T08:15:20.510788+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956120510_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
327918965576722946
|
-3660159508063819383
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81447
|
2826
|
19
|
2026-05-28T08:15:23.144584+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956123144_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-7873217691253624362
|
-3624060342283908727
|
click
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…...
|
81446
|
NULL
|
NULL
|
NULL
|
|
81448
|
2827
|
23
|
2026-05-28T08:15:22.028433+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956122028_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-5165548209905977393
|
-7627414387934682686
|
click
|
hybrid
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
PhpStormViewNeweNiCCoocKetucioTOOI-WindowFV faVsco.s ~$2 JY-20915-fix-missing-header-text-rela)proideta Kemnelonip© SyncMailbox.phpWockhrhta© InternetMessagelnterface.ph© MailChannelService.phgTextRelayServiceTest.phpo Textrelkysewice.on0 MeetinaGeneratoomcadonên OAuth2Dn Playbooks178—KeCaLAJotaeoDn Streamingla Teama Telechony#UserPilotWebhookC Abstrac Semvice cho©ActivityProviderFactory.php© ActivityService.php© ApiResponseService.oho187188189190Ceonarsneasaries oodg InsightSeatService.phpC InstantMeetingService.phgcilntecomswneoeC IpapiClient.php© IpapiService.phpC ParticipantShareService.phg©. PlanhatService.php© PlaybackService.phpPlaybackVideoOnlyService.pho© PlaybookCategoryService.php© PlaylistGeneratorinterface.php© ResolveTeamCrmConnection.ph© SimoleThrottleService.ohgC SlackService.oho© SoclalAccountService.oho)C SoftPhoneService.oho19319419S ©) TeamOwnerService.ohoC) TeamService.oho213C) TranscodeParameterResolver.ot 215C UserSemce.onC Uuidloho> M Traitc› @ UseCasesiMusAUtils>E Va cation215218Mo halnore nhr@ tnitislGrantondGtnto nhoeillliminnv nhnA Olen nhí3.env.productionclass TextRelayServiceivare tuncczon asroncurehichvarohaehtsercosusens nos moreoordemhoy,hesoeosmesshac->actPavlondio->oc-Headeneiorheaders as Sheader) 1eader->name === "X-6n-0riginal-To') tatches=Sthis->natchessxnectedPecsinent/SheaderswallueSexoectedAbias.Sexoecterhostr((!Smatches) ?Sanitize PIl by renoving plus-tag content for loggingSsanitizedOriginalto = explode( separator: *+*, Sheader->value)(0)=Log::info( message:' TextRelayService) Refused message','message id' => Snessageid,'original to sanitized' a› SsanitizedoriginaltoI):nol messase:Tex kelayservice Kerused nessace: eissing x-bn-Urzoznal-To headen'oc10 = Snessagclors present' => array nap(fn (Sh) => Sh->nane . *: • . explode( separator: *+*. Sh->value) (0 A(messaoe: "[TextRelavServicel Failed to insoect ressaac*. flge_id' => Smessageldtion' = Se->aetMessageo)anwure syceor lone"atchesExpectedReciplent(string Sreciplent, string SexpectedAlias, string SexpectedHost: bool...1 edit+v Accept Fle x- X Reject File ox cSF fiminny@localhost)HS.Jocal jiminny@blocalhost)& console [PROD)# consoe leu.2826-85-28 87:47:501 Local.INF0: Sparansnzscorylypes = nessageaddeestartHistoryId) => 359921correlazon10:YaC0//105-02715-4442-8886-7268823530901d":*87f39623-3deb-4827-aBcf-b862acc93289**7826-85-28 87:47:58 Local.IWFU: Snessagchzscomvtrace10: [CREDIT_CARD]-a8cт-0862aec93789-17876-85528 87-S8857omuotfteSoamaneIhistorylypes => messageAddecstartHistorytoll50%2cornellatiionsd"."ph67/206-7350-172h-6789-40a7456066550 "trace 3o".=62a0Rohp-d660-hcAu-h1de-R/3ceccba6at*2826-85-28 R7-59-5811 1oclTNED: Snessadels stomuEconnelatton Saw."ehf71z0h-775a.170h-h780.40.7456e01550 "ьласA S/.-6290R0/9-1640-6604-h1de-9/3cecchaf91»)2924-85.28 87-55-17 | 1o601 TNEh• SoananshistoryTypes => messageAddecAwAtU&AtAAuTAl = 26002-4d4a-b84b-a8531ca414a7"1300x.06.29 92-66-171 Jocol-1w51: Snossagchs stom.#"correlation_id":"25971837-3161-431b-adS9-e898eb48beSf*, *trace_id*:*c3463c2c-d21b-4d4a-b84b-a8531ca614a7"}(2826-85-28 88:88:531 Zocal, INF0: Sparansmistorvnvoes => nessagenddedistartHistorvidl s 350925connel atson o""naosynoo%ctheyerark -chn chcoaiieuooace aeuei aioowe ser.oSec-hsyiuhichthuOierhoR RRohieSaioetst Srassadelsrom#[CREDIT_CARD].05cc-H529269c24h7"2924-85-28 AR-95-27| Toeol TNSh: SoananeTO0У L7• Thu 28 May 11:15:21TextRelayServiceTestler henwserwietCiniishet somewnete now on stagina or oroduction?Yes. The next time the sync runs and hits a message without X-e-original-lo, the warning will now include teaoeis prescht in the log contextheckit in Cloud Watch or wherever woduet onlstac na loos go) Saarch tor• oTextRelaySeruice Refused message: miosing Xec orioins -to hesdeThe log entry will now look like"Delivered-To: catch-all""To: catchesh"The Sync runs on a schedule = check kernel pho to see now trequendyineschtouletkewinseo.tarescnectlineoloworconto.thcommnotsrhorttex.erclav.swmx=yolcan trigger it manually right now on staging/production to get the new log output immediately:docker exec -it docker lamp 1 php artisan mailbox: text-relay: syndThen check the lons straight after. If there's a refused messace in the current history window vou'll see the new nahrAeachntsrrau.n thowarninaloammodistow MarashtawetwthscehhahiNhet ehois th-@ eodeAdhotvAReinctalAcceot allXwodeurlhimewrekhirest4 spad...
|
81445
|
NULL
|
NULL
|
NULL
|
|
81449
|
2827
|
24
|
2026-05-28T08:15:24.014801+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956124014_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
327918965576722946
|
-3660159508063819383
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81450
|
2826
|
20
|
2026-05-28T08:15:25.280154+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956125280_m1.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.019444445,"height":0.02111111},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.015277778,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.014583333,"height":0.025555555},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
327918965576722946
|
-3660159508063819383
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
NULL
|
NULL
|
NULL
|
|
81451
|
2827
|
25
|
2026-05-28T08:15:29.116657+00:00
|
/Users/lukas/.screenpipe/data/data/2026-05-28/1779 /Users/lukas/.screenpipe/data/data/2026-05-28/1779956129116_m2.jpg...
|
PhpStorm
|
faVsco.js – TextRelayService.php
|
1
|
NULL
|
monitor_2
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"bounds":{"left":0.025930852,"top":0.019952115,"width":0.03856383,"height":0.025538707},"on_screen":true,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JY-20915-fix-missing-header-text-relay, menu","depth":5,"bounds":{"left":0.064494684,"top":0.019952115,"width":0.09740692,"height":0.025538707},"on_screen":true,"help_text":"Git Branch: JY-20915-fix-missing-header-text-relay","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"bounds":{"left":0.8374335,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"TextRelayServiceTest","depth":6,"bounds":{"left":0.85272604,"top":0.019952115,"width":0.062832445,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9155585,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'TextRelayServiceTest'","depth":6,"bounds":{"left":0.9268617,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"bounds":{"left":0.9381649,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"bounds":{"left":0.96609044,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"bounds":{"left":0.9773936,"top":0.019952115,"width":0.011303191,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"bounds":{"left":0.9886968,"top":0.019952115,"width":0.011303186,"height":0.025538707},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"1","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXStaticText","text":"17","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00930851,"height":0.0},"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.00731383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.006981383,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","depth":4,"on_screen":true,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Mail;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Support\\Facades\\Log;\nuse Jiminny\\Component\\Queue\\Constants;\nuse Jiminny\\Jobs\\Mailbox\\EmailTextRelay;\nuse Jiminny\\Models\\TextRelay;\nuse Google\\Service\\Gmail as GoogleGmail;\n\nclass TextRelayService\n{\n public function __construct()\n {\n $credentials = storage_path('text-relay.json');\n\n abort_unless(file_exists($credentials), 422);\n\n putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);\n }\n\n /**\n * Fetch the latest messages since the last sync.\n */\n public function sync(): array\n {\n $mailbox = config('jiminny.google_text_user');\n\n $expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';\n $expectedHost = config('jiminny.google_text_host');\n\n Log::info('[TextRelayService] Starting sync', [\n 'mailbox' => $mailbox,\n 'expected_alias' => $expectedAlias,\n 'expected_host' => $expectedHost,\n ]);\n\n $service = $this->getService($mailbox);\n\n $messageHistory = $this->getHistory($service);\n $messageIds = [];\n\n foreach ($messageHistory as $histories) {\n $messages = $histories->messagesAdded ?? [];\n\n foreach ($messages as $message) {\n $messageId = $message->message->id;\n\n if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {\n continue;\n }\n\n $relayedText = TextRelay::where('email_provider_id', $messageId)->first();\n\n if ($relayedText === null) {\n $relayedText = TextRelay::create([\n 'email_provider' => TextRelay::PROVIDER_GSUITE,\n 'email_provider_id' => $messageId,\n 'status' => TextRelay::STATUS_PROCESSING,\n ]);\n }\n\n $job = new EmailTextRelay($messageId, $relayedText);\n $job->onQueue(Constants::QUEUE_EMAILS);\n\n dispatch($job);\n\n Log::info('[TextRelayService] Successfully dispatched message', [\n 'message_id' => $messageId,\n 'text_relay_id' => $relayedText->id,\n 'queue' => Constants::QUEUE_EMAILS,\n ]);\n\n $messageIds[] = $messageId;\n }\n }\n\n Log::info('[TextRelayService] Sync completed', [\n 'mailbox' => $mailbox,\n 'messages_processed' => count($messageIds),\n 'message_ids' => array_slice($messageIds, 0, 10),\n ]);\n\n return $messageIds;\n }\n\n public function getHistory(GoogleGmail $service): array\n {\n $pageToken = null;\n $topic = config('jiminny.google_text_relay_topic');\n $messages = [];\n $historyId = \\Cache::get($topic);\n\n // If we have no history stored, WatchMailboxEvents must not have run yet :/\n if ($historyId == false) {\n $historyId = $this->refreshHistoryPoint($topic);\n }\n\n $params = [\n 'historyTypes' => 'messageAdded',\n 'startHistoryId' => $historyId,\n ];\n\n do {\n try {\n if ($pageToken) {\n $params['pageToken'] = $pageToken;\n }\n\n $historyResponse = $service->users_history->listUsersHistory(\n config('jiminny.google_text_user'),\n $params\n );\n\n $this->setHistoryPoint($topic, (int) $historyResponse->historyId);\n\n if ($historyResponse->getHistory()) {\n $messages = array_merge($messages, $historyResponse->getHistory());\n $pageToken = $historyResponse->getNextPageToken();\n }\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to fetch Gmail history', [\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n } while ($pageToken);\n\n return $messages;\n }\n\n protected function setHistoryPoint(string $topic, int $historyPoint): Carbon\n {\n $expiresAt = now()->addDay();\n\n \\Cache::put($topic, $historyPoint, $expiresAt);\n\n return $expiresAt;\n }\n\n public function getService(string $mailbox): GoogleGmail\n {\n $client = new \\Google_Client();\n $client->useApplicationDefaultCredentials();\n $client->addScope(GoogleGmail::GMAIL_MODIFY);\n $client->setAccessType('offline');\n $client->setSubject($mailbox);\n\n return new GoogleGmail($client);\n }\n\n public function refreshHistoryPoint(string $topic): int\n {\n $mailbox = config('jiminny.google_text_user');\n $service = $this->getService($mailbox);\n\n $watchRequest = new GoogleGmail\\WatchRequest();\n $watchRequest->setLabelIds(['INBOX']);\n $watchRequest->setLabelFilterAction('include');\n $watchRequest->setTopicName($topic);\n\n $watchResponse = $service->users->watch($mailbox, $watchRequest);\n\n //$expiryTimestamp = $watchResponse->expiration / 1000;\n $historyPoint = (int) $watchResponse->historyId;\n\n $this->setHistoryPoint($topic, $historyPoint);\n\n return $historyPoint;\n }\n\n private function isForCurrentEnvironment(\n GoogleGmail $service,\n string $mailbox,\n string $messageId,\n string $expectedAlias,\n string $expectedHost\n ): bool {\n try {\n $message = $service->users_messages->get($mailbox, $messageId);\n $headers = $message->getPayload()->getHeaders();\n\n foreach ($headers as $header) {\n if ($header->name === 'X-Gm-Original-To') {\n $matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);\n\n if (! $matches) {\n // Sanitize PII by removing plus-tag content for logging\n $sanitizedOriginalTo = explode('+', $header->value)[0];\n Log::info('[TextRelayService] Refused message', [\n 'message_id' => $messageId,\n 'original_to_sanitized' => $sanitizedOriginalTo,\n ]);\n }\n\n return $matches;\n }\n }\n\n Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [\n 'message_id' => $messageId,\n 'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),\n ]);\n } catch (\\Exception $e) {\n Log::error('[TextRelayService] Failed to inspect message', [\n 'message_id' => $messageId,\n 'exception' => $e->getMessage(),\n ]);\n \\Sentry::captureException($e);\n }\n\n return false;\n }\n\n private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool\n {\n $parts = explode('@', $recipient, 2);\n\n if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {\n return false;\n }\n\n $localBase = explode('+', $parts[0], 2)[0];\n\n return strcasecmp($localBase, $expectedAlias) === 0;\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.042220745,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"6","depth":4,"bounds":{"left":0.7293883,"top":0.10055866,"width":0.007978723,"height":0.015163607},"on_screen":true,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"bounds":{"left":0.7390292,"top":0.09896249,"width":0.00731383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"bounds":{"left":0.7463431,"top":0.09896249,"width":0.006981383,"height":0.018355945},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","depth":4,"bounds":{"left":0.43051863,"top":0.09736632,"width":0.32280585,"height":0.90263367},"on_screen":true,"value":"[2026-05-28 07:47:50] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:47:50] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"9acc7103-e275-4442-a80e-72ca0233ad9d\",\"trace_id\":\"87f39623-3deb-4827-a0cf-b862aec93209\"}\n[2026-05-28 07:50:57] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:50:58] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"ebf74306-735e-472b-b780-f9a7f56e4655\",\"trace_id\":\"b2a98e4e-d669-4c04-b1de-043cecc6a601\"}\n[2026-05-28 07:55:17] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359021\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 07:55:17] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"25971837-31f1-431b-ad59-e890eb40b05f\",\"trace_id\":\"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7\"}\n[2026-05-28 08:00:53] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:00:54] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"da957797-f328-4bf7-8a33-961c0cca120c\",\"trace_id\":\"34c82f30-39f2-45cf-95cc-b520260c2fb3\"}\n[2026-05-28 08:05:23] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:05:24] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"c5339dcc-46c1-45a4-81f9-ede0203ab266\",\"trace_id\":\"627196cf-0a09-465a-ab3e-10e546adfcde\"}\n[2026-05-28 08:10:44] local.INFO: $params \nArray\n(\n [historyTypes] => messageAdded\n [startHistoryId] => 359025\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}\n[2026-05-28 08:10:44] local.INFO: $messageHistory \nArray\n(\n)\n {\"correlation_id\":\"8667713e-79c8-46a6-b5a4-b13351d287da\",\"trace_id\":\"52ec740a-b685-4b96-abda-8e5ab1057ea6\"}","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"on_screen":false,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"bounds":{"left":0.011968086,"top":0.047885075,"width":0.024268618,"height":0.024740623},"on_screen":true,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.27027926,"top":1.0,"width":0.008643617,"height":0.0},"on_screen":false,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-5203598102691296047
|
-3624130711044855415
|
typing_pause
|
accessibility
|
NULL
|
Project: faVsco.js, menu
JY-20915-fix-missing-head Project: faVsco.js, menu
JY-20915-fix-missing-header-text-relay, menu
Start Listening for PHP Debug Connections
TextRelayServiceTest
Run 'TextRelayServiceTest'
Debug 'TextRelayServiceTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Code changed:
Hide
Sync Changes
Hide This Notification
1
17
Previous Highlighted Error
Next Highlighted Error
<?php
declare(strict_types=1);
namespace Jiminny\Services\Mail;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Jiminny\Component\Queue\Constants;
use Jiminny\Jobs\Mailbox\EmailTextRelay;
use Jiminny\Models\TextRelay;
use Google\Service\Gmail as GoogleGmail;
class TextRelayService
{
public function __construct()
{
$credentials = storage_path('text-relay.json');
abort_unless(file_exists($credentials), 422);
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentials);
}
/**
* Fetch the latest messages since the last sync.
*/
public function sync(): array
{
$mailbox = config('jiminny.google_text_user');
$expectedAlias = config('jiminny.deploy_region') === 'eu' ? 'catch-all-eu' : 'catch-all';
$expectedHost = config('jiminny.google_text_host');
Log::info('[TextRelayService] Starting sync', [
'mailbox' => $mailbox,
'expected_alias' => $expectedAlias,
'expected_host' => $expectedHost,
]);
$service = $this->getService($mailbox);
$messageHistory = $this->getHistory($service);
$messageIds = [];
foreach ($messageHistory as $histories) {
$messages = $histories->messagesAdded ?? [];
foreach ($messages as $message) {
$messageId = $message->message->id;
if (! $this->isForCurrentEnvironment($service, $mailbox, $messageId, $expectedAlias, $expectedHost)) {
continue;
}
$relayedText = TextRelay::where('email_provider_id', $messageId)->first();
if ($relayedText === null) {
$relayedText = TextRelay::create([
'email_provider' => TextRelay::PROVIDER_GSUITE,
'email_provider_id' => $messageId,
'status' => TextRelay::STATUS_PROCESSING,
]);
}
$job = new EmailTextRelay($messageId, $relayedText);
$job->onQueue(Constants::QUEUE_EMAILS);
dispatch($job);
Log::info('[TextRelayService] Successfully dispatched message', [
'message_id' => $messageId,
'text_relay_id' => $relayedText->id,
'queue' => Constants::QUEUE_EMAILS,
]);
$messageIds[] = $messageId;
}
}
Log::info('[TextRelayService] Sync completed', [
'mailbox' => $mailbox,
'messages_processed' => count($messageIds),
'message_ids' => array_slice($messageIds, 0, 10),
]);
return $messageIds;
}
public function getHistory(GoogleGmail $service): array
{
$pageToken = null;
$topic = config('jiminny.google_text_relay_topic');
$messages = [];
$historyId = \Cache::get($topic);
// If we have no history stored, WatchMailboxEvents must not have run yet :/
if ($historyId == false) {
$historyId = $this->refreshHistoryPoint($topic);
}
$params = [
'historyTypes' => 'messageAdded',
'startHistoryId' => $historyId,
];
do {
try {
if ($pageToken) {
$params['pageToken'] = $pageToken;
}
$historyResponse = $service->users_history->listUsersHistory(
config('jiminny.google_text_user'),
$params
);
$this->setHistoryPoint($topic, (int) $historyResponse->historyId);
if ($historyResponse->getHistory()) {
$messages = array_merge($messages, $historyResponse->getHistory());
$pageToken = $historyResponse->getNextPageToken();
}
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to fetch Gmail history', [
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
} while ($pageToken);
return $messages;
}
protected function setHistoryPoint(string $topic, int $historyPoint): Carbon
{
$expiresAt = now()->addDay();
\Cache::put($topic, $historyPoint, $expiresAt);
return $expiresAt;
}
public function getService(string $mailbox): GoogleGmail
{
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(GoogleGmail::GMAIL_MODIFY);
$client->setAccessType('offline');
$client->setSubject($mailbox);
return new GoogleGmail($client);
}
public function refreshHistoryPoint(string $topic): int
{
$mailbox = config('jiminny.google_text_user');
$service = $this->getService($mailbox);
$watchRequest = new GoogleGmail\WatchRequest();
$watchRequest->setLabelIds(['INBOX']);
$watchRequest->setLabelFilterAction('include');
$watchRequest->setTopicName($topic);
$watchResponse = $service->users->watch($mailbox, $watchRequest);
//$expiryTimestamp = $watchResponse->expiration / 1000;
$historyPoint = (int) $watchResponse->historyId;
$this->setHistoryPoint($topic, $historyPoint);
return $historyPoint;
}
private function isForCurrentEnvironment(
GoogleGmail $service,
string $mailbox,
string $messageId,
string $expectedAlias,
string $expectedHost
): bool {
try {
$message = $service->users_messages->get($mailbox, $messageId);
$headers = $message->getPayload()->getHeaders();
foreach ($headers as $header) {
if ($header->name === 'X-Gm-Original-To') {
$matches = $this->matchesExpectedRecipient($header->value, $expectedAlias, $expectedHost);
if (! $matches) {
// Sanitize PII by removing plus-tag content for logging
$sanitizedOriginalTo = explode('+', $header->value)[0];
Log::info('[TextRelayService] Refused message', [
'message_id' => $messageId,
'original_to_sanitized' => $sanitizedOriginalTo,
]);
}
return $matches;
}
}
Log::warning('[TextRelayService] Refused message: missing X-Gm-Original-To header', [
'message_id' => $messageId,
'headers_present' => array_map(fn ($h) => $h->name . ': ' . explode('+', $h->value)[0], $headers),
]);
} catch (\Exception $e) {
Log::error('[TextRelayService] Failed to inspect message', [
'message_id' => $messageId,
'exception' => $e->getMessage(),
]);
\Sentry::captureException($e);
}
return false;
}
private function matchesExpectedRecipient(string $recipient, string $expectedAlias, string $expectedHost): bool
{
$parts = explode('@', $recipient, 2);
if (count($parts) !== 2 || strcasecmp($parts[1], $expectedHost) !== 0) {
return false;
}
$localBase = explode('+', $parts[0], 2)[0];
return strcasecmp($localBase, $expectedAlias) === 0;
}
}
Sync Changes
Hide This Notification
Code changed:
Hide
6
Previous Highlighted Error
Next Highlighted Error
[2026-05-28 07:47:50] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:47:50] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"9acc7103-e275-4442-a80e-72ca0233ad9d","trace_id":"87f39623-3deb-4827-a0cf-b862aec93209"}
[2026-05-28 07:50:57] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:50:58] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"ebf74306-735e-472b-b780-f9a7f56e4655","trace_id":"b2a98e4e-d669-4c04-b1de-043cecc6a601"}
[2026-05-28 07:55:17] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359021
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 07:55:17] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"25971837-31f1-431b-ad59-e890eb40b05f","trace_id":"c3f63c2c-d21b-4d4a-b84b-a8531ca414a7"}
[2026-05-28 08:00:53] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:00:54] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"da957797-f328-4bf7-8a33-961c0cca120c","trace_id":"34c82f30-39f2-45cf-95cc-b520260c2fb3"}
[2026-05-28 08:05:23] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:05:24] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"c5339dcc-46c1-45a4-81f9-ede0203ab266","trace_id":"627196cf-0a09-465a-ab3e-10e546adfcde"}
[2026-05-28 08:10:44] local.INFO: $params
Array
(
[historyTypes] => messageAdded
[startHistoryId] => 359025
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
[2026-05-28 08:10:44] local.INFO: $messageHistory
Array
(
)
{"correlation_id":"8667713e-79c8-46a6-b5a4-b13351d287da","trace_id":"52ec740a-b685-4b96-abda-8e5ab1057ea6"}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options...
|
81449
|
NULL
|
NULL
|
NULL
|