Phase 2: Implement Domain & Mailbox persistence, Analytics, and fix pagination issues
This commit is contained in:
@@ -90,6 +90,24 @@ class ProcessIncomingEmail implements ShouldQueue
|
||||
]
|
||||
);
|
||||
|
||||
// Track analytics for receiving email
|
||||
$mailbox = \App\Models\Mailbox::where('address', $email->recipient_email)->first();
|
||||
|
||||
TrackAnalytics::dispatch(
|
||||
eventType: 'email_received',
|
||||
mailboxHash: $mailbox?->mailbox_hash ?? 'unknown',
|
||||
domainHash: $mailbox?->domain_hash ?? 'unknown',
|
||||
metadata: [
|
||||
'email_id' => $email->id,
|
||||
'sender' => $email->sender_email,
|
||||
'recipient' => $email->recipient_email,
|
||||
'attachment_count' => count($metadata['attachments'] ?? []),
|
||||
'found_mailbox' => $mailbox !== null,
|
||||
],
|
||||
ipAddress: '0.0.0.0', // Server-side event
|
||||
userAgent: 'MailOps/IncomingWorker'
|
||||
);
|
||||
|
||||
$this->ensureTtlIndex();
|
||||
|
||||
NewEmailReceived::dispatch($email);
|
||||
|
||||
48
app/Jobs/TrackAnalytics.php
Normal file
48
app/Jobs/TrackAnalytics.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class TrackAnalytics implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $eventType,
|
||||
public string $mailboxHash,
|
||||
public ?string $domainHash = null,
|
||||
public array $metadata = [],
|
||||
public ?int $userId = null,
|
||||
public string $userType = 'guest',
|
||||
public ?string $ipAddress = null,
|
||||
public ?string $userAgent = null,
|
||||
) {
|
||||
$this->onQueue('analytics');
|
||||
$this->onConnection('redis');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
\App\Models\AnalyticsEvent::create([
|
||||
'event_type' => $this->eventType,
|
||||
'mailbox_hash' => $this->mailboxHash,
|
||||
'domain_hash' => $this->domainHash,
|
||||
'user_type' => $this->userType,
|
||||
'user_id' => $this->userId,
|
||||
'ip_address' => $this->ipAddress ?? request()->ip(),
|
||||
'user_agent' => $this->userAgent ?? request()->userAgent(),
|
||||
'metadata' => $this->metadata,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user