PHP Classes

File: test1.php

Recommend this page to a friend!
  Classes of Daniel Andres Marjos   clsImap   test1.php   Download  
File: test1.php
Role: Example script
Content type: text/plain
Description: A sample on using this class
Class: clsImap
Access IMAP, POP or NNTP accounts
Author: By
Last change:
Date: 20 years ago
Size: 2,370 bytes
 

Contents

Class file image Download
<?
include("clsImap.php");

class
userinfo {
    var
$mailbox;
   
    function
userinfo($parse) {
       
$aux=explode("@",$parse);
       
       
$this->mailbox=$aux[0];
    }
   
}

class
mailinfo {

    var
$to = array();
    var
$from = array();
    var
$subject = "";
    var
$date = "";
           
    function
MailInfo($to, $from) {
       
$xto=explode(",",$to);
        for (
$x=0; $x<count($xto); $x++)
           
$this->to[]=new userinfo($xto[$x]);
       
$xfrom=explode(",",$from);
        for (
$x=0; $x<count($xfrom); $x++)
           
$this->from[]=new userinfo($xfrom[$x]);
    }
   
}

function
_headerinfo($msgno,$attch) {
    global
$messages;

   
$elmail=explode("\n",$messages[$msgno]->attachments[$attch]->content);

    for (
$i=0; $i<count($elmail); $i++){
       
$linea=$elmail[$i];
        if (
eregi("From: (.*)", $linea, $regs))
           
$from=$regs[1];
        elseif (
eregi("To: (.*)", $linea, $regs))
           
$to=$regs[1];
        elseif (
eregi("subject: (.*)", $linea, $regs))
           
$subject=$regs[1];
        elseif (
eregi("date: (.*)", $linea, $regs))
           
$date=$regs[1];
    }
   
   
$headerinfo=new mailinfo($to,$from);
   
$headerinfo->subject=$subject;
   
$headerinfo->date=$date;
   
    return
$headerinfo;
   
}

function
_body($msgno,$attch) {
    global
$messages;

   
$elmail=explode("\n",$messages[$msgno]->attachments[$attch]->content);

   
$body="";
   
$inbody=false;
    for (
$i=0; $i<count($elmail); $i++){
       
$linea=$elmail[$i];
        if (
trim($linea)=="" and ($i>0))
           
$inbody=true;
        if (
$inbody)
           
$body.=chop($linea)."\n\r";
    }
   
    return
$body;
   
}


function
dump_var($theVar,$indent=0) {

    while (list(
$k,$v)=each($theVar)) {
        for (
$p=0; $p<($indent*4); $p++) echo "&middot;";
        echo
"key $k = ";
        if (
is_array($v) or is_object($v)) {
            echo (
is_array($v)?"Array (".count($v).") elementos)":"Objeto")."<br>";
           
dump_var($v,$indent+1);
        } else {
            echo
htmlspecialchars($v)."<br>";
        }
    }
}

$mailbox=new clsImapHandler("username","password","mail.server.com");
$mailbox->open();
echo
"The mail account has ".$mailbox->Messages." messages<br>";

echo
"showing message from explicit sender<br>";
$messages=array();
for (
$i=1; $i<=$mailbox->Messages; $i++) {
   
$message=$mailbox->getMessage($i);
    if (
$message->from=="\"Dummy Sender\" <sender@server.com>") {
       
$messages[]=$message;
    }
}
echo
"We have found ".count($messages)." messages from sender@server.com<br>";

$mailbox->close();
?>