Skip to content
Snippets Groups Projects
Select Git revision
  • 1c44ff54ceabbf777428ea16cd9e1dde5260277c
  • master default protected
  • simple-task/7248-eol-check-add-node-22
  • 6877_check_iml_deployment
4 results

check_fs_errors

Blame
  • viewer.php 3.90 KiB
    <?php
    /**
     * =======================================================================
     * 
     * PHP EMAIL CATCHER
     * Read emails sent by mail() and browse them
     * 
     * 👤 Author: Axel Hahn, Institute for Medical Education, University of Bern
     * 📄 Source: <https://git-repo.iml.unibe.ch/iml-open-source/php-emailcatcher>
     * 📜 License: GNU GPL 3.0
     * 
     * ----------------------------------------------------------------------
     * 2024-10-08  v0.1  initial version
     * =======================================================================
     */
    require_once('classes/emailcatcher.class.php');
    
    
    // $sJsonFile='/tmp/mailin.txt.json';
    
    $sOpen=$_GET['open'] ?? '';
    $sShowHtml=$_GET['html'] ?? '';
    
    // ----------------------------------------------------------------------
    // FUNCTIONS
    // ----------------------------------------------------------------------
    
    
    
    function showEmail($sId)
    {
        $sReturn='';
        $oMail=new emailcatcher();
        if(!$oMail->setId($sId)){
            $sReturn.="❌ ERROR: wrong email id: $sId<br>";
        } else {
    
            $bIsHtml=strstr( $oMail->getBody(), '<html>');
            $sReturn.= '<div id="singlemessage">
                <table>
                    <tr><td>🕜 DATE</td><td>'.$oMail->getField('date')
                        .'<span class="right"><a href="?" class="button close">❌ Close</a></span>
                    </td></tr>
                    <tr><td>👤 TO</td><td>'.$oMail->getField('to').'</td></tr>
                    <tr><td colspan=2><strong>'.$oMail->getField('subject').'</strong></td></tr>
                </table>
                <br>
                <div class="content">
                    📜 Header:<br>
                    <pre>'.$oMail->getHeader().'</pre>
                    <br>🗨️ '
                    .($bIsHtml
                        ? '<a href="?open='.$sId.'&html=1" class="button">👁️ Show message as HTML</a><br><br>'
                        : 'Text only:'
                    )
                    .'<pre>'.htmlentities($oMail->getBody()).'</pre>'
                    .'<br>
                    <span class="right"><a href="?" class="button close">❌ Close</a></span><br>
                    <br>'
                .'</div>'
            .'</div>'
            ;
        }
        return $sReturn;
    }
    
    function showHtmlEmail($sId): void
    {
        $oMail=new emailcatcher();
        echo '<button onclick="history.back();return false;">back</button><br>';
        if(!$oMail->setId($sId)){
            echo "❌ ERROR: wrong email id: $sId<br>";
        } else {
            echo $oMail->getBody();
            die();
        }
    }
    // ----------------------------------------------------------------------
    // MAIN
    // ----------------------------------------------------------------------
    
    $oMail=new emailcatcher();
    $aEmails=$oMail->readEmails();
    
    $sOut='';
    $sMessage='';
    
    if(!count($aEmails)){
        $sOut='❌ No email was found.<br>';
    } else {
    
        // get a single email if id was given.
        if ($sOpen){
            if($sShowHtml=="1"){
                showHtmlEmail($sOpen);
            }
            $sMessage=showEmail($sOpen);    
        }
    
        $sOut='Messages: <strong>'.count($aEmails).'</strong><br>';
    
        foreach($aEmails as $aEmail){
    
            $sId=$aEmail['id'];
    
            $sOut.='
            <div id="'.$sId.'" class="email'.($sId==$sOpen ? ' open':'').'">
                '.(
                    $sId!=$sOpen
                        ? '✉️ <a href="?open='.$sId.'">'.$aEmail['date'].' - to '.$aEmail['to'].': '.$aEmail['subject'].'</a>'
                        : '🔶 '. $aEmail['date'].' - to '.$aEmail['to'].': '.$aEmail['subject']
                )
            .'</div>';
    
        }
    }
    
    
    
    // write html page
    
    echo "<!doctype html>
    <html>
    <head>
        <title>Email catcher :: viewer</title>
        <link rel=\"stylesheet\" href=\"viewer.css\">
    </head>
    <body>
        <h1><a href=\"?\">🕶️ Email catcher :: viewer</a></h1>
    
        <div id=\"messages\">$sOut</div>
    
        <footer>
            Email catcher
            📄 <a href=\"\">source</a>
            📗 <a href=\"\">docs</a>
        </footer>
    
        $sMessage
    
    </body>
    </html>
    ";
    
    // ----------------------------------------------------------------------