<?php
declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| ASOVERIFY MAIL VIEWER
|--------------------------------------------------------------------------
| INBOX + SENT MAIL
|
| Requires PHP IMAP extension.
|--------------------------------------------------------------------------
*/

error_reporting(E_ALL);
ini_set('display_errors', '1');


/* =========================================================
   MAIL SETTINGS
========================================================= */

$mailboxEmail = 'noreply@asoverify.com.ng';

/*
 * IMPORTANT:
 * Put your mailbox password here.
 */
$mailboxPassword = 'Sabirata@273';

$imapServer = 'mail.asoverify.com.ng';
$imapPort   = 993;


/* =========================================================
   CHECK IMAP
========================================================= */

if (!function_exists('imap_open')) {

    die('
        <div style="
            font-family:Arial;
            padding:30px;
            margin:30px;
            background:#fff3f3;
            color:#b00020;
            border-radius:12px;
        ">

            <h2>PHP IMAP Extension Missing</h2>

            <p>
                Please enable the PHP IMAP extension from cPanel.
            </p>

        </div>
    ');
}


/* =========================================================
   HELPER
========================================================= */

function e(?string $value): string
{
    return htmlspecialchars(
        (string)$value,
        ENT_QUOTES,
        'UTF-8'
    );
}


/* =========================================================
   IMAP BASE PREFIX
========================================================= */

function imapPrefix(
    string $server,
    int $port
): string {

    return
        '{' .
        $server .
        ':' .
        $port .
        '/imap/ssl/novalidate-cert}';
}


/* =========================================================
   CONNECT TO FOLDER
========================================================= */

function connectFolder(
    string $server,
    int $port,
    string $email,
    string $password,
    string $folder
) {

    /*
     * If folder is already a complete IMAP mailbox path,
     * use it exactly as returned by the server.
     */
    if (str_starts_with($folder, '{')) {

        $mailbox = $folder;

    } else {

        $mailbox =
            imapPrefix($server, $port) .
            $folder;
    }


    return @imap_open(
        $mailbox,
        $email,
        $password
    );
}


/* =========================================================
   CONNECT INBOX
========================================================= */

$inboxFolder =
    imapPrefix(
        $imapServer,
        $imapPort
    ) .
    'INBOX';


$inbox = @imap_open(
    $inboxFolder,
    $mailboxEmail,
    $mailboxPassword
);


if (!$inbox) {

    die('
        <div style="
            font-family:Arial;
            padding:30px;
            margin:30px;
            background:#fff3f3;
            color:#b00020;
            border-radius:12px;
        ">

            <h2>Unable to Connect to Inbox</h2>

            <p>' .
                e(
                    imap_last_error()
                    ?: 'Unknown IMAP error'
                ) .
            '</p>

        </div>
    ');
}


/* =========================================================
   FIND SENT FOLDER
========================================================= */

$sentFolder = null;

$sentDisplayName = '';


$serverPrefix =
    imapPrefix(
        $imapServer,
        $imapPort
    );


$mailboxes = @imap_getmailboxes(
    $inbox,
    $serverPrefix,
    '*'
);


if ($mailboxes !== false) {

    foreach ($mailboxes as $box) {

        /*
         * IMPORTANT:
         *
         * $box->name contains the COMPLETE mailbox path,
         * for example:
         *
         * {mail.asoverify.com.ng:993/imap/ssl}INBOX.Sent
         *
         * We keep this complete value.
         */

        $fullMailboxName =
            (string)$box->name;


        /*
         * Decode display name.
         */
        $displayName =
            @imap_utf7_decode(
                $fullMailboxName
            );


        if ($displayName === false) {

            $displayName =
                $fullMailboxName;
        }


        /*
         * Remove IMAP server prefix only for
         * checking the folder name.
         */

        $folderOnly =
            $displayName;


        if (
            str_starts_with(
                $folderOnly,
                '{'
            )
        ) {

            $closingBrace =
                strpos(
                    $folderOnly,
                    '}'
                );

            if (
                $closingBrace !== false
            ) {

                $folderOnly =
                    substr(
                        $folderOnly,
                        $closingBrace + 1
                    );
            }
        }


        $folderLower =
            strtolower(
                trim($folderOnly)
            );


        /*
         * Common Sent folder names.
         */

        $isSent =
            (
                $folderLower === 'sent' ||
                $folderLower === 'inbox.sent' ||
                $folderLower === 'sent items' ||
                $folderLower === 'inbox.sent items' ||
                $folderLower === 'sent mail' ||
                $folderLower === 'inbox.sent mail' ||
                str_ends_with(
                    $folderLower,
                    '.sent'
                ) ||
                str_ends_with(
                    $folderLower,
                    '.sent items'
                ) ||
                str_ends_with(
                    $folderLower,
                    '.sent mail'
                )
            );


        if ($isSent) {

            /*
             * USE THE COMPLETE MAILBOX NAME.
             */
            $sentFolder =
                $fullMailboxName;

            $sentDisplayName =
                $folderOnly;

            break;
        }
    }
}


/* =========================================================
   DECODE HEADER
========================================================= */

function decodeMimeHeader(
    string $text
): string {

    if ($text === '') {
        return '';
    }


    $decoded =
        @imap_mime_header_decode(
            $text
        );


    if (!$decoded) {
        return $text;
    }


    $result = '';


    foreach ($decoded as $part) {

        $charset =
            strtoupper(
                $part->charset ?? 'DEFAULT'
            );


        $value =
            $part->text ?? '';


        if (
            $charset !== 'DEFAULT' &&
            $charset !== 'UTF-8'
        ) {

            $converted =
                @iconv(
                    $charset,
                    'UTF-8//IGNORE',
                    $value
                );


            if ($converted !== false) {

                $value =
                    $converted;
            }
        }


        $result .= $value;
    }


    return $result;
}


/* =========================================================
   GET ADDRESS
========================================================= */

function getAddresses(
    $header,
    string $field
): string {

    if (
        !isset($header->$field) ||
        empty($header->$field)
    ) {

        return '';
    }


    $addresses = [];


    foreach (
        $header->$field
        as $address
    ) {

        $name =
            decodeMimeHeader(
                $address->personal ?? ''
            );


        $mailbox =
            $address->mailbox ?? '';


        $host =
            $address->host ?? '';


        $email = '';


        if (
            $mailbox !== '' &&
            $host !== ''
        ) {

            $email =
                $mailbox .
                '@' .
                $host;
        }


        if (
            $name !== '' &&
            $email !== ''
        ) {

            $addresses[] =
                $name .
                ' <' .
                $email .
                '>';

        } elseif (
            $email !== ''
        ) {

            $addresses[] =
                $email;

        } elseif (
            $name !== ''
        ) {

            $addresses[] =
                $name;
        }
    }


    return implode(
        ', ',
        $addresses
    );
}


/* =========================================================
   GET EMAIL BODY
========================================================= */

function getEmailBody(
    $imap,
    int $emailNumber
): string {

    $structure =
        @imap_fetchstructure(
            $imap,
            $emailNumber
        );


    if (!$structure) {
        return '';
    }


    $plain = '';
    $html  = '';


    /*
     * SIMPLE EMAIL
     */
    if (empty($structure->parts)) {

        $body =
            @imap_body(
                $imap,
                $emailNumber,
                FT_PEEK
            );


        $encoding =
            $structure->encoding ?? 0;


        if ($encoding === 3) {

            $decoded =
                base64_decode($body);


            if ($decoded !== false) {

                $body =
                    $decoded;
            }

        } elseif ($encoding === 4) {

            $body =
                quoted_printable_decode(
                    $body
                );
        }


        $subtype =
            strtoupper(
                $structure->subtype ?? ''
            );


        if ($subtype === 'HTML') {

            $html =
                $body;

        } else {

            $plain =
                $body;
        }
    }


    /*
     * MULTIPART EMAIL
     */
    else {

        foreach (
            $structure->parts
            as $partNumber => $part
        ) {

            $section =
                (string)(
                    $partNumber + 1
                );


            $body =
                @imap_fetchbody(
                    $imap,
                    $emailNumber,
                    $section,
                    FT_PEEK
                );


            $encoding =
                $part->encoding ?? 0;


            if ($encoding === 3) {

                $decoded =
                    base64_decode($body);


                if ($decoded !== false) {

                    $body =
                        $decoded;
                }

            } elseif ($encoding === 4) {

                $body =
                    quoted_printable_decode(
                        $body
                    );
            }


            $type =
                $part->type ?? 0;


            $subtype =
                strtoupper(
                    $part->subtype ?? ''
                );


            if ($type === 0) {

                if ($subtype === 'HTML') {

                    $html .=
                        $body;

                } else {

                    $plain .=
                        $body;
                }
            }
        }
    }


    /*
     * HTML
     */
    if ($html !== '') {

        /*
         * Remove scripts.
         */
        $html =
            preg_replace(
                '/<script\b[^>]*>.*?<\/script>/is',
                '',
                $html
            );


        /*
         * Remove iframe.
         */
        $html =
            preg_replace(
                '/<iframe\b[^>]*>.*?<\/iframe>/is',
                '',
                $html
            );


        /*
         * Remove object.
         */
        $html =
            preg_replace(
                '/<object\b[^>]*>.*?<\/object>/is',
                '',
                $html
            );


        /*
         * Remove embed.
         */
        $html =
            preg_replace(
                '/<embed\b[^>]*>/is',
                '',
                $html
            );


        /*
         * Remove inline JavaScript.
         */
        $html =
            preg_replace(
                '/\son\w+\s*=\s*("[^"]*"|\'[^\']*\'|[^\s>]+)/i',
                '',
                $html
            );


        return $html;
    }


    /*
     * PLAIN TEXT
     */
    return nl2br(
        htmlspecialchars(
            trim($plain),
            ENT_QUOTES,
            'UTF-8'
        )
    );
}


/* =========================================================
   BUILD MAIL ENTRY
========================================================= */

function buildMailEntry(
    $header,
    int $number,
    string $folder,
    string $type
): array {

    return [

        'number' =>
            $number,

        'folder' =>
            $folder,

        'type' =>
            $type,

        'subject' =>
            decodeMimeHeader(
                $header->subject
                ?? '(No Subject)'
            ),

        'from' =>
            getAddresses(
                $header,
                'from'
            ),

        'to' =>
            getAddresses(
                $header,
                'to'
            ),

        'date' =>
            $header->date
            ?? '',

        'timestamp' =>
            isset($header->udate)
                ? (int)$header->udate
                : 0,

        'seen' =>
            empty($header->Unseen)
    ];
}


/* =========================================================
   CURRENT VIEW
========================================================= */

$view =
    strtolower(
        trim(
            (string)(
                $_GET['view'] ?? 'inbox'
            )
        )
    );


if (
    $view !== 'sent'
) {

    $view = 'inbox';
}


/* =========================================================
   SELECTED EMAIL
========================================================= */

$selectedEmail =
    isset($_GET['email'])
        ? (int)$_GET['email']
        : 0;


/* =========================================================
   OPENED EMAIL
========================================================= */

$openedEmail = null;


/* =========================================================
   INBOX EMAIL COUNT
========================================================= */

$totalInboxEmails =
    imap_num_msg($inbox);


/* =========================================================
   INBOX LIST
========================================================= */

$inboxEmails = [];


if ($totalInboxEmails > 0) {

    for (
        $i = $totalInboxEmails;
        $i >= 1 && count($inboxEmails) < 100;
        $i--
    ) {

        $header =
            @imap_headerinfo(
                $inbox,
                $i
            );


        if (!$header) {
            continue;
        }


        $inboxEmails[] =
            buildMailEntry(
                $header,
                $i,
                'INBOX',
                'incoming'
            );
    }
}


/* =========================================================
   SENT CONNECTION
========================================================= */

$sent = null;

$sentEmails = [];

$totalSentEmails = 0;


if ($sentFolder !== null) {

    /*
     * IMPORTANT:
     *
     * connectFolder now recognizes that
     * $sentFolder is already a COMPLETE
     * IMAP mailbox path.
     */
    $sent =
        connectFolder(
            $imapServer,
            $imapPort,
            $mailboxEmail,
            $mailboxPassword,
            $sentFolder
        );


    if ($sent) {

        $totalSentEmails =
            imap_num_msg($sent);


        if ($totalSentEmails > 0) {

            for (
                $i = $totalSentEmails;
                $i >= 1 && count($sentEmails) < 100;
                $i--
            ) {

                $header =
                    @imap_headerinfo(
                        $sent,
                        $i
                    );


                if (!$header) {
                    continue;
                }


                $sentEmails[] =
                    buildMailEntry(
                        $header,
                        $i,
                        $sentFolder,
                        'sent'
                    );
            }
        }
    }
}


/* =========================================================
   OPEN INBOX EMAIL
========================================================= */

if (
    $selectedEmail > 0 &&
    $view === 'inbox' &&
    $selectedEmail <= $totalInboxEmails
) {

    /*
     * Mark as read.
     */
    @imap_setflag_full(
        $inbox,
        (string)$selectedEmail,
        "\\Seen"
    );


    $header =
        @imap_headerinfo(
            $inbox,
            $selectedEmail
        );


    if ($header) {

        $openedEmail = [

            'type' =>
                'incoming',

            'subject' =>
                decodeMimeHeader(
                    $header->subject
                    ?? '(No Subject)'
                ),

            'from' =>
                getAddresses(
                    $header,
                    'from'
                ),

            'to' =>
                getAddresses(
                    $header,
                    'to'
                ),

            'date' =>
                $header->date ?? '',

            'body' =>
                getEmailBody(
                    $inbox,
                    $selectedEmail
                )
        ];
    }
}


/* =========================================================
   OPEN SENT EMAIL
========================================================= */

if (
    $selectedEmail > 0 &&
    $view === 'sent' &&
    $sent !== false &&
    $sent !== null &&
    $selectedEmail <= $totalSentEmails
) {

    $header =
        @imap_headerinfo(
            $sent,
            $selectedEmail
        );


    if ($header) {

        $openedEmail = [

            'type' =>
                'sent',

            'subject' =>
                decodeMimeHeader(
                    $header->subject
                    ?? '(No Subject)'
                ),

            'from' =>
                getAddresses(
                    $header,
                    'from'
                ),

            'to' =>
                getAddresses(
                    $header,
                    'to'
                ),

            'date' =>
                $header->date ?? '',

            'body' =>
                getEmailBody(
                    $sent,
                    $selectedEmail
                )
        ];
    }
}


/* =========================================================
   CLOSE SENT
========================================================= */

if ($sent) {

    /*
     * Don't close yet if opened email needs
     * the connection? The body has already
     * been read, so it is safe.
     */
    @imap_close($sent);
}

?>
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta
    name="viewport"
    content="width=device-width, initial-scale=1.0"
>

<title>ASOVERIFY Mail</title>


<style>

* {
    box-sizing: border-box;
}


body {

    margin: 0;

    font-family:
        Arial,
        Helvetica,
        sans-serif;

    background: #f2f5f9;

    color: #172033;
}


/* =========================================================
   HEADER
========================================================= */

.header {

    background:
        linear-gradient(
            135deg,
            #0b3d91,
            #0875d1
        );

    color: white;

    padding: 18px 20px;
}


.header h1 {

    margin: 0;

    font-size: 22px;
}


.header p {

    margin: 6px 0 0;

    opacity: .85;

    font-size: 13px;
}


/* =========================================================
   NAV
========================================================= */

.mail-nav {

    display: flex;

    gap: 10px;

    padding: 14px 15px;

    background: white;

    border-bottom:
        1px solid #e5e7eb;
}


.nav-button {

    text-decoration: none;

    padding: 10px 16px;

    border-radius: 8px;

    font-size: 13px;

    font-weight: bold;
}


.nav-inbox {

    background: #e8f2ff;

    color: #0b3d91;
}


.nav-sent {

    background: #eee7ff;

    color: #6d28d9;
}


.nav-button.active {

    box-shadow:
        0 0 0 2px
        rgba(11,61,145,.15);
}


/* =========================================================
   CONTAINER
========================================================= */

.container {

    max-width: 1100px;

    margin: 20px auto;

    padding: 0 15px;
}


/* =========================================================
   CARD
========================================================= */

.card {

    background: white;

    border-radius: 12px;

    box-shadow:
        0 3px 15px
        rgba(0,0,0,.08);

    overflow: hidden;
}


/* =========================================================
   MAIL ITEM
========================================================= */

.mail-item {

    display: block;

    text-decoration: none;

    color: inherit;

    padding: 16px;

    border-bottom:
        1px solid #e8ebef;

    transition: .2s;
}


.mail-item:hover {

    background: #f5f9ff;
}


.mail-item.unread {

    background: #edf6ff;
}


.mail-subject {

    font-size: 15px;

    font-weight: bold;

    margin-bottom: 7px;
}


.mail-from {

    color: #475569;

    font-size: 13px;

    margin-bottom: 5px;
}


.mail-date {

    color: #7b8794;

    font-size: 12px;
}


/* =========================================================
   BADGES
========================================================= */

.badge {

    display: inline-block;

    padding: 4px 8px;

    border-radius: 20px;

    font-size: 10px;

    margin-left: 5px;

    font-weight: bold;
}


.badge-new {

    background: #0b7dda;

    color: white;
}


.badge-sent {

    background: #7c3aed;

    color: white;
}


/* =========================================================
   OPENED EMAIL
========================================================= */

.opened {

    padding: 22px;
}


.back {

    display: inline-block;

    margin-bottom: 18px;

    text-decoration: none;

    color: #0b3d91;

    font-weight: bold;
}


.opened h2 {

    margin-top: 0;

    font-size: 21px;
}


.email-type {

    display: inline-block;

    padding: 6px 10px;

    border-radius: 20px;

    font-size: 10px;

    font-weight: bold;

    margin-bottom: 14px;
}


.email-type.incoming {

    background: #dbeafe;

    color: #1e40af;
}


.email-type.sent {

    background: #ede9fe;

    color: #6d28d9;
}


.meta {

    background: #f5f7fa;

    padding: 15px;

    border-radius: 8px;

    margin-bottom: 20px;
}


.meta div {

    margin: 7px 0;

    font-size: 14px;
}


.body {

    padding: 10px;

    overflow-x: auto;

    line-height: 1.6;
}


.body img {

    max-width: 100%;

    height: auto;
}


/* =========================================================
   EMPTY
========================================================= */

.empty {

    padding: 50px 20px;

    text-align: center;

    color: #64748b;
}


/* =========================================================
   WARNING
========================================================= */

.warning {

    margin-top: 15px;

    padding: 13px;

    border-radius: 8px;

    background: #fff7ed;

    color: #9a3412;

    border:
        1px solid #fed7aa;

    font-size: 13px;
}


/* =========================================================
   REFRESH
========================================================= */

.refresh {

    display: inline-block;

    margin-top: 15px;

    background: white;

    color: #0b3d91;

    border:
        1px solid #0b3d91;

    padding: 9px 15px;

    border-radius: 7px;

    text-decoration: none;

    font-size: 13px;
}


/* =========================================================
   MOBILE
========================================================= */

@media(max-width:600px) {

    .header h1 {

        font-size: 19px;
    }


    .container {

        padding: 0 10px;
    }


    .opened {

        padding: 15px;
    }


    .body {

        font-size: 14px;
    }

}

</style>

</head>


<body>


<!-- =====================================================
     HEADER
====================================================== -->

<div class="header">

    <h1>
        📧 ASOVERIFY Mail
    </h1>

    <p>
        <?php echo e($mailboxEmail); ?>
    </p>

</div>


<!-- =====================================================
     NAVIGATION
====================================================== -->

<div class="mail-nav">

    <a
        href="inbox_val.php?view=inbox"
        class="nav-button nav-inbox <?php
            echo $view === 'inbox'
                ? 'active'
                : '';
        ?>"
    >
        📥 Inbox
    </a>


    <a
        href="inbox_val.php?view=sent"
        class="nav-button nav-sent <?php
            echo $view === 'sent'
                ? 'active'
                : '';
        ?>"
    >
        📤 Sent

        <?php if ($totalSentEmails > 0): ?>

            (<?php echo $totalSentEmails; ?>)

        <?php endif; ?>

    </a>

</div>


<div class="container">


<?php if ($openedEmail): ?>


<!-- =====================================================
     OPENED EMAIL
====================================================== -->

<div class="card">

    <div class="opened">


        <a
            href="inbox_val.php?view=<?php
                echo $view;
            ?>"
            class="back"
        >
            ← Back to
            <?php echo $view === 'sent'
                ? 'Sent'
                : 'Inbox'; ?>
        </a>


        <?php if (
            $openedEmail['type'] === 'sent'
        ): ?>

            <div class="email-type sent">
                📤 SENT EMAIL
            </div>

        <?php else: ?>

            <div class="email-type incoming">
                📥 INCOMING EMAIL
            </div>

        <?php endif; ?>


        <h2>

            <?php echo e(
                $openedEmail['subject']
            ); ?>

        </h2>


        <div class="meta">


            <div>

                <strong>
                    From:
                </strong>

                <?php echo e(
                    $openedEmail['from']
                ); ?>

            </div>


            <div>

                <strong>
                    To:
                </strong>

                <?php echo e(
                    $openedEmail['to']
                ); ?>

            </div>


            <div>

                <strong>
                    Date:
                </strong>

                <?php echo e(
                    $openedEmail['date']
                ); ?>

            </div>


        </div>


        <div class="body">

            <?php
            echo $openedEmail['body'];
            ?>

        </div>


    </div>

</div>


<?php else: ?>


<!-- =====================================================
     EMAIL LIST
====================================================== -->

<div class="card">


<?php if ($view === 'sent'): ?>


    <!-- =================================================
         SENT MAIL
    ================================================== -->

    <?php if (empty($sentEmails)): ?>


        <div class="empty">

            <h3>
                📤 No Sent Emails
            </h3>

            <?php if ($sentFolder === null): ?>

                <p>
                    The mail server did not expose a
                    standard Sent folder.
                </p>

            <?php elseif ($sent === false): ?>

                <p>
                    The Sent folder was found, but
                    the server did not allow it to
                    be opened.
                </p>

            <?php else: ?>

                <p>
                    There are no messages in the
                    Sent folder.
                </p>

            <?php endif; ?>

        </div>


    <?php else: ?>


        <div class="mail-list">


        <?php foreach (
            $sentEmails as $mail
        ): ?>


            <?php

            $url =
                'inbox_val.php?view=sent' .
                '&email=' .
                (int)$mail['number'];

            ?>


            <a
                href="<?php
                    echo e($url);
                ?>"
                class="mail-item"
            >


                <div class="mail-subject">

                    <?php echo e(
                        $mail['subject']
                    ); ?>


                    <span class="badge badge-sent">
                        SENT
                    </span>

                </div>


                <div class="mail-from">

                    <strong>
                        To:
                    </strong>

                    <?php echo e(
                        $mail['to']
                    ); ?>

                </div>


                <div class="mail-date">

                    <?php echo e(
                        $mail['date']
                    ); ?>

                </div>


            </a>


        <?php endforeach; ?>


        </div>


    <?php endif; ?>


<?php else: ?>


    <!-- =================================================
         INBOX
    ================================================== -->

    <?php if (empty($inboxEmails)): ?>


        <div class="empty">

            <h3>
                📭 No Incoming Emails
            </h3>

            <p>
                Your inbox is currently empty.
            </p>

        </div>


    <?php else: ?>


        <div class="mail-list">


        <?php foreach (
            $inboxEmails as $mail
        ): ?>


            <?php

            $url =
                'inbox_val.php?view=inbox' .
                '&email=' .
                (int)$mail['number'];

            ?>


            <a
                href="<?php
                    echo e($url);
                ?>"
                class="mail-item <?php
                    echo !$mail['seen']
                        ? 'unread'
                        : '';
                ?>"
            >


                <div class="mail-subject">

                    <?php echo e(
                        $mail['subject']
                    ); ?>


                    <?php if (
                        !$mail['seen']
                    ): ?>

                        <span class="badge badge-new">
                            NEW
                        </span>

                    <?php endif; ?>

                </div>


                <div class="mail-from">

                    <strong>
                        From:
                    </strong>

                    <?php echo e(
                        $mail['from']
                    ); ?>

                </div>


                <div class="mail-date">

                    <?php echo e(
                        $mail['date']
                    ); ?>

                </div>


            </a>


        <?php endforeach; ?>


        </div>


    <?php endif; ?>


<?php endif; ?>


</div>


<?php endif; ?>


<!-- =====================================================
     SENT FOLDER WARNING
====================================================== -->

<?php if (
    $sentFolder === null
): ?>

<div class="warning">

    ⚠️ The server did not expose a recognizable
    Sent folder. If your cPanel mail app shows a
    Sent folder, tell me its exact name and I can
    add it directly.

</div>

<?php endif; ?>


<a
    href="inbox_val.php?view=<?php
        echo $view;
    ?>"
    class="refresh"
>
    🔄 Refresh Mail
</a>


</div>


</body>

</html>


<?php

/* =========================================================
   CLOSE INBOX
========================================================= */

@imap_close($inbox);

?>