Code Snippets

  

PHP Source Code


Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 131,942 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,897 people online right now. Registration is fast and FREE... Join Now!





Imap class

I quickly delevoped this for a email based auction script I'm working on now and then. It is similar to the php5 ftp class found at php.net/ftp but is written with php4.3 in mind.

Submitted By: snoj
Actions:
Rating:
Views: 6,584

Language: PHP

Last Modified: June 21, 2005
Instructions: Read the documentation at php.net/imap for more info on imap function.

I have not looked at every function. But for most you do not need to include the resource varible as this class does it automaticly.

Example:
imap_headers($_imap_resource);
//becomes
$imap_object->headers();

Snippet


  1. <?php
  2. class imap {
  3.      var $handle;
  4.      function imap($add, $user, $pass) {
  5.           $this->handle = imap_open($add, $user, $pass);
  6.           overload(__CLASS__);
  7.           return true;
  8.      }
  9.      
  10.      function __call($function, $arguments, &$return) {
  11.      //funny thing about php4.3.x is that you need &$return but you never need to put it in the call for the method....hmmm...
  12.           if(function_exists('imap_'.$function)) {
  13.                // Prepend the imap resource to the arguments array
  14.                array_unshift($arguments, $this->handle);
  15.  
  16.                // Call the PHP function
  17.                $return = call_user_func_array('imap_' . $function, $arguments);
  18.           } else {
  19.                die('"imap_'.$function.'" does not exist.');
  20.           }
  21.           return true;
  22.      }
  23. }
  24. //Small example usage.
  25. $imap_object = new imap("{mail.someserver.com/pop3:110/notls}INBOX", 'username', 'password');
  26. print_r($imap_object->headers());
  27. ?>

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month