added logic for updating user profile plus other bug fixes

This commit is contained in:
Kwesi Banson Jnr
2026-03-16 16:41:32 +00:00
parent 9cd017fb9a
commit 72180de8e4
30 changed files with 1346 additions and 49 deletions

57
app/Libs/ImapService.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace App\Libs;
class ImapService
{
protected $connection;
public function __construct()
{
/*
$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$username = "kwesibanson@gmail.com"; // env('IMAP_USERNAME', 'your.email@gmail.com');
$password = "yutbgxtlqwwepalr"; //env('IMAP_PASSWORD', 'your-app-password');
*/
$hostname = '{imap-mail.outlook.com:993/imap/ssl/novalidate-cert}INBOX';
$username = "kwesi_banson@hotmail.com"; // env('IMAP_USERNAME', 'your.email@gmail.com');
$password = "uyligiqtreyubvvp"; //"okxixwlqppkpfepy"; //env('IMAP_PASSWORD', 'your-app-password');
$this->connection = @imap_open($hostname, $username, $password);
if (!$this->connection) {
throw new \Exception('Cannot connect: ' . imap_last_error());
}
}
public function getLatestEmails($limit = 10): array
{
$emails = imap_search($this->connection, 'ALL', SE_UID);
if (!$emails) {
return [];
}
rsort($emails); // Newest first
$result = [];
foreach (array_slice($emails, 0, $limit) as $uid) {
$header = imap_headerinfo($this->connection, imap_msgno($this->connection, $uid), FT_UID);
$body = imap_fetchbody($this->connection, imap_msgno($this->connection, $uid), 1, FT_UID);
$body = quoted_printable_decode($body);
$result[] = [
'subject' => isset($header->subject) ? imap_utf8($header->subject) : '(No Subject)',
'from' => $header->from[0]->mailbox . '@' . $header->from[0]->host,
'date' => $header->date ?? 'Unknown',
'body' => substr(strip_tags($body), 0, 200) . '...',
];
}
return $result;
}
public function __destruct()
{
if ($this->connection) {
imap_close($this->connection);
}
}
}