Location: PHPKode > projects > Jwapmail > Jwapmail/html/mbox.lib.php
<?
	// $Header: /cvsroot/jwapmail/Jwapmail/html/mbox.lib.php,v 1.2 2003/10/13 21:29:15 mrbadi Exp $

	/**********************************************************************
	 *
	 * a libray used for jmail
	 *
	 * Copyright (C) 2002 3WSI <http://3wsi.com)
	 *
	 * Author : Nasir Simbolon <hide@address.com>
	 *
	 * This program  is open source; you can redistribute it and/or modify
	 * it under the terms of the GNU General Public License as published by
	 * the Free Software Foundation; either version 2 of the License, or
	 * (at your option) any later version
	 * This program is distributed in the hope that it will be useful,
	 * but WITHOUT ANY WARRANTY; without even the implied warranty of
	 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	 * GNU General Public License <http://www.opensource.org/licenses/gpl-license.html>
	 * for a complete version of the license
	 *
	 *********************************************************************/

	function listMbox ($imap_conn) {
		global $cmd_tag;

		$buff = 1024;

		unset ($mailbox);

		$cmd = "$cmd_tag LIST \"\" * \r\n";
		$res = imapCmd ($imap_conn, $cmd, $buff);

		$mboxes = explode("\r\n", $res);

		while (list ($key, $val) = each ($mboxes)) {
			if (ereg ("^\*", $val)) {
				ereg ('\"([^\"]+)\"$', $val, $mbox);
				$mailbox[] = $mbox[1];
			}
		}

		return $mailbox;
	}

	function mboxNummsg ($imap_conn, $mbox, $stat = 'Recent') {
		global $cmd_tag;

		$stat = strtoupper ($stat);

		$buff = 1024;

		$cmd  = "$cmd_tag SELECT $mbox \r\n";
		$res = imapCmd ($imap_conn, $cmd, $buff);

		$res = ereg ("\* ([0-9]+) $stat", $res, $s);

		return $s[1];
	}

	function listMsgheaders ($imap_conn, $mbox, $start, $end, $headers) {
		global $cmd_tag;

		$buff = 1024;

		// Select mailbox
		$cmd = "$cmd_tag SELECT $mbox \r\n";
		$s = imapCmd ($imap_conn, $cmd, $buff);

		// Fetch headers
		$cmd = $cmd_tag . "1 FETCH $start:$end BODY[header.fields ($headers)] \r\n";
		$res = imapCmd ($imap_conn, $cmd, $buff);

		$header = explode (' ', $headers);
		$t = count ($header);
		$msg = explode ("*", $res);
		$t1 = count ($msg);

		unset ($msg_header);

		$c = 0;

		for($i = ($t1 - 1); $i >= 0; $i--) {
			if(! $msg[$i])
				continue;

			$ss = explode ("\n", $msg[$i]);
			$css = count ($ss);

			for($k = 0; $k < $t; $k++) {
				for($j = 0; $j < $css; $j++)
					ereg($header[$k] . ": (.*)", $ss[$j], $tmp);

				$msg_header[$c][$header[$k]] = $tmp[1];
			}

			$msg_header[$c]['msgno'] = $i;

			$c++;
		}

		return $msg_header;
	}

	function getBodystructure ($imap_conn, $mbox, $msgno) {
		global $cmd_tag;

		$buff = 1024;

		// Select mailbox
		$cmd = "$cmd_tag SELECT $mbox \r\n";
		$s = imapCmd ($imap_conn, $cmd, $buff);

		// Fetch headers
		$cmd = $cmd_tag . "1 FETCH $msgno BODYSTRUCTURE \r\n";
		$res = imapCmd ($imap_conn, $cmd, $buff);

		return $res;
	}

	function getBody ($imap_conn, $mbox, $msgno, $mime = 1) {
		global $cmd_tag;

		$buff = 1024;

		// Select mailbox
		ImapSelect ($imap_conn, $mbox);

		// Fetch headers
		$res = imapFetch ($imap_conn, $msgno, $mime);

		$res = ereg_replace ("^\*.*}\r\n", '', $res);
		$res = ereg_replace ("\r\n)\r\n", '', $res);
		$res = ereg_replace ("$cmd_tag.+\r\n", '', $res);

		return $res;
	}

	function deleteMsg ($imap_conn, $mbox, $msgno) {
		global $cmd_tag;

    imapSelect ($imap_conn, $mbox);

		imapSetflag ($imap_conn, $msgno, '(\DELETED)');

		imapExpunge ($imap_conn);

		return;
	}

	function moveMsg ($imap_conn, $from, $msgno, $to) {
		ImapSelect ($imap_conn, $from);

		imapCopy ($imap_conn, $msgno, $to);

		deleteMsg ($imap_conn, $msgno);

		imapExpunge ($imap_conn);

		return;
	}
?>
Return current item: Jwapmail