Back to index

php5  5.3.10
Functions | Variables
mail_include.inc File Reference

Go to the source code of this file.

Functions

 setup_test_mailbox ($mailbox_suffix, $message_count, &$new_mailbox=null, $msg_type="simple")
 Create a test mailbox and populate with msgs.
 create_mailbox ($imap_stream, $mailbox_suffix, $message_count, $msg_type="simple")
 Create mailbox and fill with generic emails.
 populate_mailbox ($imap_stream, $mailbox, $message_count, $msg_type="simple")
 Populate a mailbox with generic emails.
 get_mailbox_name ($mailbox)
 Get the mailbox name from a mailbox decription, i.e strip off server details.

Variables

 $server = '{localhost}'
 $default_mailbox = "INBOX"
 $domain = "example.com"
 $admin_user = "webmaster"
 $username = "$admin_user@$domain"
 $password = 'p4ssw0rd'
 $users = array("webmaster", "info", "admin", "foo")
 $mailbox_prefix = "phpttest"

Function Documentation

create_mailbox ( imap_stream,
mailbox_suffix,
message_count,
msg_type = "simple" 
)

Create mailbox and fill with generic emails.

Parameters:
resource$imap_stream
string$mailbox

Definition at line 55 of file mail_include.inc.

                                                                                           {
       global $default_mailbox, $mailbox_prefix;
       $mailbox = $default_mailbox . "." . $mailbox_prefix . $mailbox_suffix;
       
       $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*');
       
       // check mailbox does not already exist
       if ($mailboxes) {
              foreach($mailboxes as $value) {
                     if ($value->name == $mailbox) {
                            exit ("TEST FAILED : Mailbox '$mailbox' already exists\n");
                     }
              }
       }      

       if (imap_createmailbox($imap_stream, $mailbox) === false) {
              return false;
       }
       
       // Add number of test msgs requested
       if ($message_count > 0) {
              populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type);
       }      
       
       return $mailbox;
}

Here is the call graph for this function:

get_mailbox_name ( mailbox)

Get the mailbox name from a mailbox decription, i.e strip off server details.

Parameters:
stringmailbox complete mailbox name
Returns:
mailbox name

Definition at line 140 of file mail_include.inc.

                                   {

       if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) {
              echo "Unrecpognized mailbox name\n";
              return false;
       }

       return $match[1];
}
populate_mailbox ( imap_stream,
mailbox,
message_count,
msg_type = "simple" 
)

Populate a mailbox with generic emails.

Parameters:
resource$imap_stream
string$mailbox

Definition at line 88 of file mail_include.inc.

                                                                                       {

       global $users, $domain;

       for($i = 1; $i <= $message_count; $i++) {
              if ($msg_type == "simple") {
                     $msg =  "From: foo@anywhere.com\r\n"
                            . "To: $users[0]@$domain\r\n"
                            . "Subject: test$i\r\n"
                            . "\r\n"
                            . "$i: this is a test message, please ignore\r\n";
              } else {
                     $envelope["from"]= "foo@anywhere.com";
                     $envelope["to"]  = "$users[0]@$domain";
                     $envelope["subject"] = "Test msg $i";
              
                     $part1["type"] = TYPEMULTIPART;
                     $part1["subtype"] = "mixed";
                     
                     $part2["type"] = TYPETEXT;
                     $part2["subtype"] = "plain";
                     $part2["description"] = "imap_mail_compose() function";
                     $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx";
                     
                     $part3["type"] = TYPETEXT;
                     $part3["subtype"] = "plain";
                     $part3["description"] = "Example";
                     $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy";
                     
                     $part4["type"] = TYPETEXT;
                     $part4["subtype"] = "plain";
                     $part4["description"] = "Return Values";
                     $part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz";
                     
                     $body[1] = $part1;
                     $body[2] = $part2;
                     $body[3] = $part3;
                     $body[4] = $part4;
                     
                     $msg = imap_mail_compose($envelope, $body);
              }
       
              imap_append($imap_stream, $mailbox, $msg);
       }
}
setup_test_mailbox ( mailbox_suffix,
message_count,
&$  new_mailbox = null,
msg_type = "simple" 
)

Create a test mailbox and populate with msgs.

, string mailbox_suffix Suffix used to uniquely identify mailboxes

Parameters:
intmessage_count number of test msgs to be written to new mailbox
Returns:
IMAP stream to new mailbox on sucesss; FALSE on failure

Definition at line 20 of file mail_include.inc.

                                                                                                        {
       global $server, $default_mailbox, $username, $password;
       
       // open a stream to default mailbox
       $imap_stream = imap_open($default_mailbox, $username, $password);

       if ($imap_stream === false) {
              echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
              return false;
       }      
       
       echo "Create a temporary mailbox and add " . $message_count .  " msgs\n";
       $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type);
       if ($new_mailbox === false) {
          echo "Cant create a temporary mailbox: " . imap_last_error(). "\n";
          return false;
       }
       
       echo ".. mailbox '$new_mailbox' created\n";
       
       // reopen stream to new mailbox
       if (imap_reopen($imap_stream, $new_mailbox) === false) {
              echo "cant re-open '$new_mailbox' mailbox: " . imap_last_error() . "\n";
              return false;
       }
       
       return $imap_stream;
}

Here is the call graph for this function:


Variable Documentation

$admin_user = "webmaster"

Definition at line 6 of file mail_include.inc.

$default_mailbox = "INBOX"

Definition at line 4 of file mail_include.inc.

$domain = "example.com"

Definition at line 5 of file mail_include.inc.

$mailbox_prefix = "phpttest"

Definition at line 10 of file mail_include.inc.

$password = 'p4ssw0rd'

Definition at line 8 of file mail_include.inc.

$server = '{localhost}'

Definition at line 3 of file mail_include.inc.

$username = "$admin_user@$domain"

Definition at line 7 of file mail_include.inc.

$users = array("webmaster", "info", "admin", "foo")

Definition at line 9 of file mail_include.inc.