๐Ÿ“‚ File Browser

/AgentAIv3_backup
๐ŸŒ™ Dark Mode
๐ŸŽฏ Quick Launch:

๐Ÿ“ Directories

๐Ÿ“ tmp/ ๐Ÿ”“ Open
๐Ÿ“ vendor/ ๐Ÿ”“ Open

๐Ÿ“„ Files

๐Ÿ˜ chat_handler.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ chat_handler_test.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ check_db.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ cleanup.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ config.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ database.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ delete_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ fetch_emails.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ get_email.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ index.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ index_minimal.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ index_simple.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ logout.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ mark_read.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ new_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ oauth2callback.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ rename_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐ŸŽจ style.css
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ switch_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ sync_emails.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_error.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_session.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_session2.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_session_check.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_simple.php
โ–ถ Open ๐Ÿ“„ View Source

๐Ÿ“„ Source: sync_emails.php

<?php
require_once 'config.php';
require_once 'database.php';
require_once 'vendor/autoload.php';

session_start();

if (!isset($_SESSION['access_token'])) {
    die("Nu eศ™ti autentificat. Logheazฤƒ-te mai รฎntรขi.");
}

function getEmailBodyContent($service, $messageId) {
    try {
        $message = $service->users_messages->get('me', $messageId, ['format' => 'full']);
        $payload = $message->getPayload();
        
        $decode = function($data) {
            return base64_decode(strtr($data, '-_', '+/'));
        };
        
        if ($payload->getBody() && $payload->getBody()->getData()) {
            $body = $decode($payload->getBody()->getData());
            if (!empty(trim($body))) {
                $body = strip_tags($body);
                $body = preg_replace('/\s+/', ' ', $body);
                return substr(trim($body), 0, 2000);
            }
        }
        
        if ($payload->getParts()) {
            foreach ($payload->getParts() as $part) {
                if ($part->getBody() && $part->getBody()->getData()) {
                    $body = $decode($part->getBody()->getData());
                    if (!empty(trim($body))) {
                        $body = strip_tags($body);
                        $body = preg_replace('/\s+/', ' ', $body);
                        return substr(trim($body), 0, 2000);
                    }
                }
            }
        }
        return "";
    } catch (Exception $e) {
        return "";
    }
}

echo "๐Ÿ”„ รŽncep sincronizarea emailurilor...\n";

$client = new Google\Client();
$client->setAccessToken($_SESSION['access_token']);
$service = new Google\Service\Gmail($client);
$db = new InboxDatabase();

$optParams = ['maxResults' => 500, 'labelIds' => ['INBOX']];
$messages = $service->users_messages->listUsersMessages('me', $optParams);

$count = 0;
if ($messages->getMessages()) {
    foreach ($messages->getMessages() as $msg) {
        // Verificฤƒ dacฤƒ emailul existฤƒ deja
        $existing = $db->getEmails(1, false, 0);
        // (implementare simplificatฤƒ)
        
        $message = $service->users_messages->get('me', $msg->getId(), [
            'format' => 'metadata',
            'metadataHeaders' => ['From', 'Subject', 'Date']
        ]);
        
        $headers = $message->getPayload()->getHeaders();
        $from = '';
        $subject = '';
        $date = '';
        
        foreach ($headers as $header) {
            if ($header->getName() == 'From') $from = $header->getValue();
            if ($header->getName() == 'Subject') $subject = $header->getValue();
            if ($header->getName() == 'Date') $date = $header->getValue();
        }
        
        try {
            $dateObj = new DateTime($date);
            $dateObj->setTimezone(new DateTimeZone('Europe/Bucharest'));
            $dateFormatted = $dateObj->format('Y-m-d H:i:s');
        } catch (Exception $e) {
            $dateFormatted = date('Y-m-d H:i:s');
        }
        
        $content = getEmailBodyContent($service, $msg->getId());
        
        $email = [
            'id' => $msg->getId(),
            'thread_id' => $msg->getThreadId(),
            'from' => $from,
            'subject' => $subject,
            'date' => $dateFormatted,
            'content' => $content,
            'is_read' => 0,
            'labels' => ''
        ];
        
        $db->saveEmail($email);
        $count++;
        
        if ($count % 50 == 0) {
            echo "โœ“ $count emailuri salvate...\n";
        }
    }
}

$stats = $db->getStats();
echo "\nโœ… Sincronizare completฤƒ!\n";
echo "๐Ÿ“ง Total emailuri: {$stats['total']}\n";
echo "๐Ÿ“ฌ Necitite: {$stats['unread']}\n";
echo "๐Ÿ“… Cel mai vechi: {$stats['oldest']}\n";
echo "๐Ÿ†• Cel mai nou: {$stats['newest']}\n";
?>
โ† Back