⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 email.class.inc.php

📁 This is the script which used on 10minutemail.com for temporary email.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                            );
                            
        if (!$mail->open($mailbox)) {
            return false;
        }


        // Number of messages in mailbox
        $number = 0;
        $mail->number($number);
        if ($number <= 0) {
            $mail->close();
            return false;
        }
            
        t12l_system_debug::add_message('Mailbox Status', $number . ' mail(s) in mailbox.', 'debug');
        
        $email_number = $this->download_email_num;
        if ($number < $this->download_email_num) {
            $email_number = $number;
        }
        
        // Check To: headers
        for ($i = 1; $i <= $email_number; $i++)
        {
            $message = $mail->fetch_message($i);
            $mail->mime_decode($i);
            
            if (!$to = $mail->get_header($i, 'to')) {                        
                // Delete e-mail
                $mail->delete_message($i); 
                continue;
            }
            
            $to = explode(',', $to);
            $num = sizeof($to);
            for ($t = 0; $t < $num; $t++)
            {
                $mail_address = $to[$t];
                
                if (strpos($mail_address, '<') !== false) {
                    $mail_address = substr($mail_address, strpos($mail_address, '<') + 1);
                }
                
                if (strpos($mail_address, '>') !== false) {                
                    $mail_address = substr($mail_address, 0, strpos($mail_address, '>'));
                }
                
                $mail_address = trim($mail_address);
                $mail_host    = substr($mail_address, strpos($mail_address, '@') + 1);

                if ($mail_host != $t12l['email_address_host_name']) {
                    // Delete e-mail 
                    $mail->delete_message($i);
                    continue;
                }
                
                // Count number of received e-mails
                t12l_setting::increase('received_emails');
                
                // Check address in database
                $address            = $mail_address;
                $address_id         = md5($address);
                $address_timestamp  = t12l_time::current_timestamp() - $this->lifetime;
                $sql = "SELECT  address_id 
                        FROM    " . T12L_ADDRESS_TABLE . " 
                        WHERE   address_id = ? 
                        AND     address_timestamp > ?";
                if (!$res = t12l_database::query($sql, array($address_id, $address_timestamp))) {
                    return false;
                }
                if ($res->numRows() > 0) {
                    t12l_system_debug::add_message('Mail Status', 'Mail is valid: ' . $address, 'debug');
                    
                    $subject    = $mail->get_header($i, 'subject');
                    $body       = $mail->get_body($i);
                    $from       = $mail->get_header($i, 'from');
                    if ($this->insert_mail($address, $from, $subject, $body)) {
                        // Delete e-mail
                        $mail->delete_message($i);
                    }
                } else {
                    // Delete e-mail
                    $mail->delete_message($i);
                    t12l_system_debug::add_message('Mail Status', 'Mail is NOT valid: ' . $address, 'debug');
                    
                    // Count number of expired e-mails
                    t12l_setting::increase('expired_emails');
                }
            }
        }
        if ($this->delete_emails == true) {
            $mail->perform_delete();
        }        
        $mail->close();
        
        
        // Return number of mails in mailbox
        return $number;
    }

//------------------------------------------------------------------------------




    /**
     * Write mail data to database
     * 
     */
    function insert_mail($address, $from, $subject, $body)
    {                
        // Write into comment table
        if (!$mail_id = t12l_database::next_id('mail')) {
            return false;
        }
        
        $mail_data = array( 'mail_id'           => $mail_id,
                            'mail_address_id'   => md5($address),
                            'mail_from'         => $from,
                            'mail_subject'      => $subject,
                            'mail_excerpt'      => substr($body, 0, $this->excerpt_length),
                            'mail_body'         => $body,
                            'mail_timestamp'    => t12l_time::current_timestamp(),
                            );
        if ($res = t12l_database::insert('mail', $mail_data)) {
            return true;
        }
    }          

//------------------------------------------------------------------------------




    /**
     * Get mail details from database
     * 
     * @access public
     */
    function get_mail($mail)
    {
        global $t12l;
        
        if (!is_numeric($mail)) {
            return false;
        }
        if (!t12l_session::get('address_id')) {
            return false;
        }
        
        $sql = "SELECT  m.*
                FROM    " . T12L_MAIL_TABLE . " AS m
                WHERE   m.mail_id = ?
                AND     m.mail_address_id = ?";
        t12l_system_debug::add_message('SQL Statement get_mail()', $sql, 'debug');
        if ($db = t12l_database::query($sql, array((int)$mail, t12l_session::get('address_id')))) {
            $res = $db->fetchRow();
            if (PEAR::isError($res)) {
                t12l_system_debug::add_message($res->getMessage(), $res->getDebugInfo(), 'error', $res->getBacktrace());
                t12l_system_debug::add_message('SQL Statement', $sql, 'error');
                return false;
            }
    
            if (sizeof($res) > 0) {
                
                // Enhance user data
                $frontend_text = $res['mail_body'];
                
                $frontend_text = preg_replace('/<a href="(.*?)">(.*?)<\\/a>/i', '<a href="$1">$2 -&gt; $1</a>', $frontend_text);
                $frontend_text = preg_replace('/<http(.*?)>/i', 'http$1', $frontend_text);
                $frontend_text = strip_tags($frontend_text);                
                
                if ($t12l['message_body_format'] != 'html') {
                    $frontend_text = nl2br(htmlentities($frontend_text));
                }
                
                
                $enhance = array(
                            'frontend_date'         => t12l_time::format_date($res['mail_timestamp']),
                            'frontend_time'         => t12l_time::format_time($res['mail_timestamp']),
                            'frontend_text'         => $frontend_text,
                            'frontend_subject'      => htmlentities(strip_tags($res['mail_subject'])), 
                            'frontend_from'         => htmlentities($res['mail_from'])                
                            );

                $final  = array_merge($res, $enhance);
                
                t12l_module::call_module('frontend_content', $final, $t12l['module_additional']);
                return $final;
            } else {
                $t12l['message'][] = $t12l['text']['txt_mail_not_found'];
                return false;
            }
        }

    }

// -----------------------------------------------------------------------------



    /**
     * Send reply e-mail
     * 
     */
    function send_reply($mail_id)
    {
        global $t12l;
        
        if (!$mail_data = $this->get_mail($mail_id)) {
            return false;
        }
        
        $mail_data['comment']               = $t12l['_post']['text'];
        $mail_data['email']                 = '';
        $mail_data['homepage']              = '';
        $mail_data['comment_author_ip']     = getenv('REMOTE_ADDR');
        $mail_data['name']                  = t12l_session::get('address_email');
        
        $page_data = array(
                        'page_allow_comment'    => ''
                        );
        t12l_module::call_module('frontend_save_content', $mail_data, $page_data);

        // Reply message blocked
        if ($page_data['page_allow_comment'] == 'N') {
            return false;
        }
        
        $search = array("\r", "\n", "%0A", "%0D");
        
        
        // Prepare to
        $reply_to = str_replace($search, '', $mail_data['mail_from']);
        
        // Prepare subject
        $reply_subject = str_replace($search, '', $mail_data['mail_subject']);
        $reply_subject = 'RE: ' . $reply_subject;
        
        // Prepare body
        $reply_body = htmlspecialchars(strip_tags($t12l['_post']['text']));        
        
        
        $detail_template                = 'reply.tpl.txt';
        $t12l['alternative_template']   = 'mail';
    
        // Start output handling
        $out = new t12l_output($detail_template);
        $out->assign('reply_body', $reply_body); 
        $reply_coutput = $out->finish_mail();
        
        // Send mail off
        include 'mail.class.inc.php';        
        if (t12l_mail::send($reply_to, 
                            $reply_subject,                            
                            $reply_coutput, 
                            t12l_session::get('address_email'))) {
                                
            // Count number of sent e-mails
            t12l_setting::increase('sent_emails');
            
            return true;
        }
    }          

//------------------------------------------------------------------------------



    /**
     * Delete old mails and addresses
     * 
     */
    function delete_expired()
    {
        $timestamp = (t12l_time::current_timestamp() - $this->lifetime);
        
        // Delete e-mails
        $where = " mail_timestamp < ? LIMIT 500";
        $data = array($timestamp);
        if (!$res = t12l_database::delete(T12L_MAIL_TABLE, $where, $data)) {
            return false;
        }
        
        // Delete addresses
        $where = " address_timestamp < ? LIMIT 500";
        $data = array($timestamp);
        if ($res = t12l_database::delete(T12L_ADDRESS_TABLE, $where, $data)) {
            return true;
        }
    }          

//------------------------------------------------------------------------------




} // End of class








?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -