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

📄 email.class.inc.php

📁 This is the script which used on 10minutemail.com for temporary email.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

/** 
 * GentleSource Temporary E-mail - email.class.inc.php
 * 
 * (C) Ralf Stadtaus http://www.gentlesource.com/
 */


require_once 'database.class.inc.php';




/**
 * Manage e-mails
 * 
 */
class t12l_email
{
    
    
    
    /**
     * Number of characters in excerpt
     */
    var $excerpt_length = 200;
    
    var $delete_emails  = true;
    var $maxlength      = 20;    
    var $runs           = 10;
    var $runtime        = 300;
    
    /**
     * Lifetime of an email address in seconds
     */
    var $lifetime   = 900;
    
    /**
     * Number of e-mails to be downloaded during one connection to the mailbox
     */
    var $download_email_num = 200;
    
    /**
     * Number of connections to the mailbox during one download attempt
     */
    var $download_connection_num = 3;
    
// -----------------------------------------------------------------------------




    /**
     * Constructor
     * 
     */
    function t12l_email()
    {
        global $t12l;
        
        $this->lifetime = t12l_time::convert_to_seconds($t12l['lifetime'], $t12l['lifetime_unit']);        
    }
    
// -----------------------------------------------------------------------------




    /**
     * Get e-mail address
     * 
     * @access public
     */
    function get_address($set = false)
    {
        // Dispose of old e-mail                
        if (t12l_session::get('address_timestamp') < (t12l_time::current_timestamp() - $this->lifetime)) {
            if ($this->destroy_address()) {
                if ($address = $this->new_address($set)) {
                    $address['time_left'] = $this->lifetime;
                    return $address;
                } else {
                    return false;
                }
            }
        }
        
        // Get address from existing session
        if ($address = t12l_session::get()) { 
            $address['time_left'] = $this->lifetime - (t12l_time::current_timestamp() - $address['address_timestamp']);
            return $address;
        }
        
        // Create new e-mail
        if ($address = $this->new_address($set)) {
            $address['time_left'] = $this->lifetime;
            return $address;
        } else {
            return false;
        }
    }
    
// -----------------------------------------------------------------------------




    /**
     * Reset time
     * 
     * @access public
     */
    function reset_time()
    {        
        // Create new address
        $address_email      = t12l_session::get('address_email');
        $address_id         = md5($address_email);
        $address_timestamp  = t12l_time::current_timestamp();
        
        t12l_session::add(array('address_timestamp' => $address_timestamp));
             
        // Update timestamp in e-mail table
        $data   = array('mail_timestamp' => $address_timestamp);
        $where  = " mail_address_id = ? ";
        $where_data = array($address_id); 
        if ($res = t12l_database::update('mail', $data, $where, $where_data)) {
            // Update timestamp in address table
            $data  = array('address_timestamp' => $address_timestamp);
            $where = " address_id = ? AND address_session_id = ?";
            $where_data = array($address_id, session_id());
            if ($res = t12l_database::update('address', $data, $where, $where_data)) {
                return true;
            }
        }
    }

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




    /**
     * Create new address
     * 
     * @access public
     */
    function new_address($set = false)
    {   
        global $t12l;
        
        if ($set == true and isset($t12l['_post']['setemailaddress'])) {
            $address_email = $t12l['_post']['setemailaddress'] . '@' . $t12l['email_address_host_name'];
        } else {
        
            // Create new address
            $address_email      = $this->create_address(8);
        }
        
        
        $address_id         = md5($address_email);
        $address_timestamp  = t12l_time::current_timestamp();
        
             
        // Create new entry        
        $data = array(  'address_id'                => $address_id,
                        'address_email'             => $address_email,
                        'address_timestamp'         => $address_timestamp,
                        'address_session_id'        => session_id(),
                        );
                         
        // Write address to database
        if ($res = t12l_database::insert('address', $data)) {
            
            // Write address to session
            $session = array(   'address_id'        => $address_id,
                                'address_email'     => $address_email,
                                'address_timestamp' => $address_timestamp,
                                );
            t12l_session::add($session);
            
            // Write address statistics
            t12l_setting::increase('created_addresses');
            
            return $data;
        }
    }

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




    /**
     * Create e-mail
     * 
     */
    function create_address($length, $run = 1)
    {
        global $t12l;
        require_once 'Text/Password.php'; 
        $email_address = Text_Password::create($length) . '@' . $t12l['email_address_host_name'];
        $address_id = md5($email_address);
        $sql = "SELECT  address_id FROM " . T12L_ADDRESS_TABLE . " 
                WHERE   address_id = ? ";
        if (!$res = t12l_database::query($sql, array($address_id))) {
            return $email_address;
        }
        if ($res->numRows() > 0) {
            if ($run >= $this->runs) {
                $run = 0;
                $length++;
                if ($length >= $this->maxlength) {
                    t12l_system_debug::add_message('Create Address', 'Too Much Runs', 'error');
                    return false;
                }
            }
            $email_address = $this->create_address($length, ++$run);
        }
        return $email_address;        
    }          

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




    /**
     * Dispose of e-mail
     * 
     */
    function destroy_address()
    {
        $session = array(   'address_id'        => '',
                            'address_email'     => '',
                            'address_timestamp' => '',
                            );
        t12l_session::add($session);
        return true;
    }          

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




    /**
     * Trigger download of e-mails
     * 
     */
    function trigger_mail_download()
    {   
        global $t12l;
        
        @ini_set('max_execution_time', $this->runtime);
        
        if (!function_exists('imap_open')
                or $t12l['alternative_mail_download'] == true) {
            require_once 'mailbox.class.inc.php';        
        } else {
            require_once 'mailboximap.class.inc.php';
        }
        
        for ($i = 1; $i <= $this->download_connection_num; $i++)
        {
            $downloaded_emails = $this->mail_download();
            if ($downloaded_emails == false
                    or $downloaded_emails <= 0) {
                t12l_system_debug::add_message('Trigger Mail Download', 'Number of connections: ' . $i, 'debug');
                return false;
            }
        }
        
        t12l_system_debug::add_message('Trigger Mail Download', 'Some mails remaining in mailbox', 'debug');
    }          

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




    /**
     * Download e-mails and write content to database
     * 
     */
    function mail_download()
    {   
        global $t12l;
        
        if (!function_exists('imap_open')
                or $t12l['alternative_mail_download'] == true) {        
            $mail = new t12l_mailbox($this->delete_emails);
        } else {        
            $mail = new t12l_mailboximap();
        }
        
        // Connect to mailbox
        $mailbox_path = 'pop3';
        $mailbox_port = $t12l['mailbox_port'];
        if ($t12l['mailbox_connect_ssl'] == 'Y' 
                and $t12l['alternative_mail_download'] != true) {
            $mailbox_path = 'pop3/ssl';
            $mailbox_port = $t12l['mailbox_port_ssl'];
        }
        $mailbox = array(   'hostname'  => $t12l['mailbox_hostname'],
                            'path'      => $mailbox_path,
                            'port'      => $mailbox_port,
                            'user'      => $t12l['mailbox_username'],
                            'password'  => $t12l['mailbox_password'],

⌨️ 快捷键说明

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