Public Member Functions | Data Fields

fetchSitMail Class Reference

Public Member Functions

 fetchSitMail ($username, $password, $email, $server= 'localhost', $servertype= 'pop', $port= '', $options= '')
 connect ()
 getNumUnreadEmails ()
 getAttachments ($id, $path)
 messageBody ($id)
 getMessageHeader ($id)
 deleteEmail ($id)
 iso8859Decode ($text)
 archiveEmail ($id)

Data Fields

 $username
 $password
 $server
 $email
 $mailbox
 $servertype

Detailed Description

Definition at line 16 of file fetchSitMail.class.php.


Member Function Documentation

archiveEmail ( id  ) 

Definition at line 155 of file fetchSitMail.class.php.

References $CONFIG, $id, debug_log(), and global.

    {
        global $CONFIG;
        if ($CONFIG['debug']) debug_log("Moving mail to {$CONFIG['email_archive_folder']} folder");
        return imap_mail_move($this->mailbox, $id, $CONFIG['email_archive_folder']) OR debug_log(imap_last_error());
    }

connect (  ) 

Definition at line 63 of file fetchSitMail.class.php.

References debug_log().

    {
        $this->mailbox = imap_open($this->server, $this->username,
                                   $this->password, CL_EXPUNGE);
        if ($this->mailbox)
        {
            return TRUE;
        }
        else
        {
            debug_log(imap_last_error());
            return FALSE;
        }
    }

deleteEmail ( id  ) 

Definition at line 145 of file fetchSitMail.class.php.

References $id, and debug_log().

    {
        imap_delete($this->mailbox, $id) OR debug_log(imap_last_error());
    }

fetchSitMail ( username,
password,
email,
server = 'localhost',
servertype = 'pop',
port = '',
options = '' 
)

Definition at line 25 of file fetchSitMail.class.php.

References $CONFIG, $email, $password, $servertype, $username, and global.

    {
        global $CONFIG;
        if (!empty($CONFIG['email_incoming_folder']))
        {
            $folder = $CONFIG['email_incoming_folder'];
        }
        else
        {
            $folder = 'INBOX';
        }
        if ($servertype == 'imap')
        {
            if (empty($port))
            {
                $port = '143';
            }
            $connectionString = "{{$server}:{$port}/imap{$options}".
                                 "/user={$username}}$folder";
        }
        else
        {
            if (empty($port))
            {
                $port = '110';
            }
            $connectionString = "{{$server}:{$port}/pop3{$options}".
                                "/user={$username}}$folder";
        }
        $this->username = $username;
        $this->password = $password;
        $this->server = $connectionString;
        $this->email = $email;
        $this->servertype = $servertype;
    }

getAttachments ( id,
path 
)

Definition at line 84 of file fetchSitMail.class.php.

References $filename, $fp, $id, $parts, and $path.

    {
        $parts = imap_fetchstructure($this->mailbox, $id);
        $attachments = array();

        //FIXME if we do an is_array() here it breaks howver if we don't
        //we get foreach errors
        foreach($parts->parts as $key => $value)
        {
            $encoding = $parts->parts[$key]->encoding;
            if($parts->parts[$key]->ifdparameters)
            {
                $filename = $parts->parts[$key]->dparameters[0]->value;
                $message = imap_fetchbody($this->mailbox, $id, $key + 1);

                switch($encoding)
                {
                    case 0:
                        $message = imap_8bit($message);
                    case 1:
                        $message = imap_8bit ($message);
                    case 2:
                        $message = imap_binary ($message);
                    case 3:
                        $message = imap_base64 ($message);
                    case 4:
                        $message = quoted_printable_decode($message);
                    case 5:
                    default:
                        $message = $message;
                }

                $fp = fopen($path.$filename,"w");
                fwrite($fp, $message);
                fclose($fp);
                $attachments[] = $filename;
            }
        }
        return $attachments;

    }

getMessageHeader ( id  ) 

Definition at line 140 of file fetchSitMail.class.php.

References $id.

    {
        return imap_fetchheader($this->mailbox, $id);
    }

getNumUnreadEmails (  ) 

Definition at line 78 of file fetchSitMail.class.php.

References count.

    {
        $headers = imap_headers($this->mailbox);
        return count($headers);
    }

iso8859Decode ( text  ) 

Definition at line 150 of file fetchSitMail.class.php.

References $text.

    {
        return imap_utf7_encode($text);
    }

messageBody ( id  ) 

Definition at line 126 of file fetchSitMail.class.php.

References $CONFIG, $id, debug_log(), and global.

    {
        global $CONFIG;
        if ($CONFIG['debug']) debug_log("Retrieving message {$id} from server\n");
        if (imap_body($this->mailbox, $id))
        {
            return imap_body($this->mailbox, $id);
        }
        else
        {
            debug_log("Died on message {$id} with: ".imap_last_error());
        }
    }


Field Documentation

$email

Definition at line 21 of file fetchSitMail.class.php.

Referenced by fetchSitMail().

$mailbox

Definition at line 22 of file fetchSitMail.class.php.

$password

Definition at line 19 of file fetchSitMail.class.php.

Referenced by fetchSitMail().

$server

Definition at line 20 of file fetchSitMail.class.php.

$servertype

Definition at line 23 of file fetchSitMail.class.php.

Referenced by fetchSitMail().

$username

Definition at line 18 of file fetchSitMail.class.php.

Referenced by fetchSitMail().


The documentation for this class was generated from the following file:

For more help developing with SiT! see http://sitracker.org/wiki/DevelopmentHowTo

© 2008-2011 Support Incident Tracker

Tsohost Logo