Hey, Would you like to work at Home ?? Just click here No need to pay, just register free and activate your account and get data Entry Work at your Home.

Thursday, December 6, 2007

imap.class.php

imap.class.php is used to retrieve email from given mailbox in secure way.

You need to provide hostname,username , password, port
It retrieve email from your mailbox. You are flexible to use this class as you wish.


<?php
/*
+----------------------------------------------------------------------+
| BasiliX - Copyright (C) 2000-2002 Murat Arslan <arslanm@basilix.org> |
| Contributions from: |
| Mike Peters <mike@ice2o.com> |
+----------------------------------------------------------------------+
*/


// IMAP package, this is used to handle imap related functions easier
// -----------------------------------------------------------------------
class IMAP {
var $imapstr = 0;
var $user = "";
var $pass = "";
var $host = "";
var $port = "";

function IMAP() {
// do nothing
}

// create an imap connection
function open($username, $password, $host, $port, $notls = 0) {
if($notls>0)$notls_str="/notls";
$i = @imap_open("{" . $host . ":" . $port . $notls_str . "}INBOX", $username, $password);
if(!$i) return false;
$this->imapstr = $i;
$this->user = $username;
$this->pass = $password;
$this->host = $host;
$this->port = $port;
return true;
}

// close the imap connection

function close() {
if($this->imapstr) imap_close($this->imapstr);
$this->imapstr = 0;
return true;
}

// are we connected?
function ifok() {
if(!$this->imapstr) return false;
return true;
}

// create a mbox
function crtmbox($mbox) {
if(!$this->ifok()) return false;
return imap_createmailbox($this->imapstr, "{" . $this->host . ":" . $this->port . "}" . $mbox);
}

// delete a mbox

function delmbox($mbox) {
if(!$this->ifok()) return false;
return imap_deletemailbox($this->imapstr, "{" . $this->host . ":" . $this->port . "}" . $mbox);
}

// rename a mbox

function renmbox($old, $new) {
if(!$this->ifok()) return false;
return imap_renamemailbox($this->imapstr,
"{" . $this->host . ":" . $this->port . "}" . $old,
"{" . $this->host . ":" . $this->port . "}" . $new);
}

// list the subscribed mboxes in a dir (cyrus/courier)

function lstscrbed($dir) {
if(!$this->ifok()) return false;
return imap_listsubscribed($this->imapstr, "{" . $this->host . ":" . $this->port . "}", $dir);
}

// list the mboxes in a dir
function lstmbox($dir) {
if(!$this->ifok()) return false;
return imap_listmailbox($this->imapstr, "{" . $this->host . ":" . $this->port . "}", $dir);
}

function getmailboxes($dir) {
if(!$this->ifok()) return false;
return imap_getmailboxes($this->imapstr, "{" . $this->host . ":" . $this->port . "}", $dir);
}
function getmboxes($dir) {
$mboxes = $this->getmailboxes($dir);
$i = 0;
$ret = array();
if(empty($mboxes)) return $ret;
while(list($key, $val) = each($mboxes)) {
$delim = $val->delimiter;
$name = imap_utf7_decode($val->name);
$name_arr = explode($delim, $name);
$j = count($name_arr) - 1;
$mbox_name = $name_arr[$j];
if($mbox_name == "") continue; // the DIRECTORY itself

$ret[$i++] = $mbox_name;
}
sort($ret);
return $ret;
}

// reopen the desired mbox (just the name of the mbox)
function reopbox($mbox) {
if(!$this->ifok()) return false;
return imap_reopen($this->imapstr, "{" . $this->host . ":" . $this->port . "}" . $mbox);
}

// reopen the desired mbox (full mbox name should be given as $mbox)

function reopbox2($mbox) {
if(!$this->ifok()) return false;
return imap_reopen($this->imapstr, $mbox);
}

// mailbox info
function mboxinfo() {
if(!$this->ifok()) return false;
return imap_mailboxmsginfo($this->imapstr);
}

// sort the mbox
function mboxsrt($criteria, $reverse) {
if(!$this->ifok()) return false;
return imap_sort($this->imapstr, $criteria, $reverse, SE_NOPREFETCH);
}

// retrieve the header of the message

function msghdr($msgnum) {
if(!$this->ifok()) return false;
return imap_header($this->imapstr, $msgnum);
}

// get the UID of the message
function msguid($msgnum) {
if(!$this->ifok()) return false;
return imap_uid($this->imapstr, $msgnum);
}

// get the NO of the message
function msgno($msguid) {
if(!$this->ifok()) return false;
return imap_msgno($this->imapstr, $msguid);
}

// fetch the structure

function ftchstr($msgnum) {
if(!$this->ifok()) return false;
return imap_fetchstructure($this->imapstr, $msgnum);
}

// fetch the header of the message
function ftchhdr($msgnum) {
if(!$this->ifok()) return false;
return imap_fetchheader($this->imapstr, $msgnum);
}


// delete the specified message
function rmmail($uid) {
if(!$this->ifok()) return false;
$msgno = $this->msgno($uid);
return imap_delete($this->imapstr, $msgno);
}

// move the specifed msg to mbox B

function mvmail($uid, $tombox) {
if(!$this->ifok()) return false;
return imap_mail_move($this->imapstr, $uid, $tombox, CP_UID);
}

// expunge the mailbox
function expng() {
if(!$this->ifok()) return false;
return imap_expunge($this->imapstr);
}

// fetch the body of the message
function ftchbody($msgno, $part) {
if(!$this->ifok()) return false;
return imap_fetchbody($this->imapstr, $msgno, $part, NONE);
}

// set the flags

function setflg($seq, $flg) {
if(!$this->ifok()) return false;
return imap_setflag_full($this->imapstr, $seq, $flg);
}

// search messages
function srch($q) {
if(!$this->ifok()) return false;
return imap_search($this->imapstr, $q, SE_UID);
}

// append to sent mail
function apnd($m, $b) {
if(!$this->ifok()) return false;
return @imap_append($this->imapstr, "{" . $this->host . ":" . $this->port . "}" . $m, $b);
}
}

$imap = new IMAP;

?>


1 comment:

Unknown said...

is this applicable for gmail?

Your Ad Here