๐Ÿ“‚ File Browser

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

๐Ÿ“ Directories

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

๐Ÿ“„ Files

๐Ÿ“„ README.md
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ“ README.txt
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ“ README_content.txt
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ chat_handler.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ check_auth.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ cleanup.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ“„ composer.json
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ database.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ debug_email.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ debug_email_parts.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ debug_emails.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ delete_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ fetch_emails.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ find_models.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ gemini_direct.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ get_chats.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ get_email.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ index.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ index_simple.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ index_test.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
๐Ÿ˜ refresh_token.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ rename_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ session_config.php
โ–ถ Open ๐Ÿ“„ View Source
๐ŸŽจ style.css
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ switch_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ sync_emails.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_ajax.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_api.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_cmd.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_curl.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_db.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_db_ops.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_endpoint.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_ollama.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_ollama_direct.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_openrouter.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_shell.php
โ–ถ Open ๐Ÿ“„ View Source

๐Ÿ“„ Source: get_email.php

<?php
session_name('INBOXZERO');
session_start();

header('Content-Type: application/json');

if (!isset($_SESSION['access_token'])) {
    echo json_encode(['error' => 'Not authenticated']);
    exit();
}

$input = json_decode(file_get_contents('php://input'), true);
$emailId = $input['email_id'] ?? '';

if (!$emailId) {
    echo json_encode(['error' => 'No email ID provided']);
    exit();
}

try {
    require_once 'vendor/autoload.php';
    
    $client = new Google\Client();
    $client->setAccessToken($_SESSION['access_token']);
    $service = new Google\Service\Gmail($client);
    
    $message = $service->users_messages->get('me', $emailId, ['format' => 'full']);
    $payload = $message->getPayload();
    
    $decode = function($data) {
        return base64_decode(strtr($data, '-_', '+/'));
    };
    
    $body = "";
    
    // Cautฤƒ text/plain mai รฎntรขi
    if ($payload->getParts()) {
        foreach ($payload->getParts() as $part) {
            if ($part->getMimeType() == 'text/plain' && $part->getBody() && $part->getBody()->getData()) {
                $body = $decode($part->getBody()->getData());
                break;
            }
        }
    }
    
    // Dacฤƒ nu gฤƒseศ™te text/plain, ia HTML ศ™i curฤƒศ›ฤƒ
    if (empty($body) && $payload->getBody() && $payload->getBody()->getData()) {
        $body = $decode($payload->getBody()->getData());
    }
    
    if (empty($body) && $payload->getParts()) {
        foreach ($payload->getParts() as $part) {
            if ($part->getMimeType() == 'text/html' && $part->getBody() && $part->getBody()->getData()) {
                $body = $decode($part->getBody()->getData());
                break;
            }
        }
    }
    
    if (empty($body)) {
        echo json_encode(['content' => '(No content in this email)']);
        exit();
    }
    
    // Curฤƒศ›are HTML - eliminฤƒ tot ce nu e text
    $body = preg_replace('/<style[^>]*>.*?<\/style>/is', '', $body);
    $body = preg_replace('/<script[^>]*>.*?<\/script>/is', '', $body);
    $body = preg_replace('/<head[^>]*>.*?<\/head>/is', '', $body);
    $body = preg_replace('/<meta[^>]*>/i', '', $body);
    $body = preg_replace('/<link[^>]*>/i', '', $body);
    $body = preg_replace('/<title[^>]*>.*?<\/title>/is', '', $body);
    
    // Extrage doar textul
    $body = strip_tags($body);
    $body = html_entity_decode($body, ENT_QUOTES | ENT_HTML5, 'UTF-8');
    
    // Curฤƒศ›are text
    $body = preg_replace('/\s+/', ' ', $body);
    $body = trim($body);
    
    // Eliminฤƒ URL-uri lungi
    $body = preg_replace('/https?:\/\/[^\s]+/i', '[link]', $body);
    
    // Eliminฤƒ footer
    $body = preg_replace('/unsubscribe.*$/i', '', $body);
    $body = preg_replace('/View in browser.*$/i', '', $body);
    $body = preg_replace('/ยฉ.*$/i', '', $body);
    
    // Dacฤƒ textul e prea scurt, รฎnseamnฤƒ cฤƒ e doar CSS
    if (strlen($body) < 50) {
        $body = "(No readable text content in this email)";
    }
    
    // Limiteazฤƒ lungimea
    if (strlen($body) > 2000) {
        $body = substr($body, 0, 2000) . "\n\n...(truncated)";
    }
    
    echo json_encode(['content' => $body]);
    
} catch (Exception $e) {
    echo json_encode(['error' => $e->getMessage()]);
}
?>
โ† Back