Location: PHPKode > projects > Jwapmail > Jwapmail/html/imap.lib.php
<?
	// $Header: /cvsroot/jwapmail/Jwapmail/html/imap.lib.php,v 1.1 2003/07/09 11:44:50 nasir Exp $

	/**********************************************************************
	 * 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
	 *
	 * a IMAP client command library
	 * compliance to RFC2060 (see docs/rfc2060.html)
	 *
	 **********************************************************************/

	/* Create a socket connection to IMAP server
	*/
	function imapOpen() {
		$fp = fsockopen ($_SESSION['host'], $_SESSION['port'], $errno, $errstr, 15);
		if(! $fp)
			return $errstr . '(' . $errno . ')';

		$res =  fgets ($fp, 1024);
		if (ereg ('OK', $res))
			return $fp;
		else
			return false;
	}

	/* Log in to IMAP server
		 rfc2060 section 6.2.2
	 */

	function imapLogin ($imap_conn) {
		global $cmd_tag;

		$buffsize = 256;

		$cmd = "$cmd_tag login " . $_SESSION['username'] . " " .
			$_SESSION ['password'] . " \r\n";

		$res = imapCmd ($imap_conn, $cmd, $buffsize);
		if (ereg ('OK', $res))
			return true;
		else
			return false;
	}

	/* Execute IMAP client command
	*/
	function imapCmd ($imap_conn, $cmd, $buffsize) {
		global $cmd_tag;

		fputs ($imap_conn, $cmd, strlen ($cmd));

		while (strpos ($res, $cmd_tag) === false) {
			if(! ($res .= fgets ($imap_conn, $buffsize)))
				return $res;
		}

		return $res;
	}

	/* Switch to mbox
		 rfc2060 section 6.3.1
	 */
	function imapSelect ($imap_conn, $mbox) {
		global $cmd_tag;

		$buff = 1024;

		$cmd = "$cmd_tag SELECT $mbox \r\n";

		$s = imapCmd ($imap_conn, $cmd, $buff);

		return;
	}

	/* Set flag of message
		 rfc2060 section 6.4.6
	 */
	function imapSetflag ($imap_conn, $msgno, $flag) {
		global $cmd_tag;

		$buff = 1024;

		$cmd = "$cmd_tag STORE $msgno FLAGS $flag\r\n";

		$res = imapCmd ($imap_conn, $cmd, $buff);

		return;
	}

	/* Commit delete message
		 rfc2060 section 6.4.3
	 */
	function imapExpunge ($imap_conn) {
		global $cmd_tag;

		$buff = 256;

		$cmd = "$cmd_tag EXPUNGE \r\n";

		$res = imapCmd ($imap_conn, $cmd, $buff);

		return;
	}

	/* Fetch message
		 rfc2060 section 6.4.5
	 */
	function imapFetch ($imap_conn, $msgno, $mime) {
		global $cmd_tag;

		$buff = 256;

		$cmd = $cmd_tag . "1 FETCH $msgno $arg BODY[$mime] \r\n";

		$res = imapCmd ($imap_conn, $cmd, $buff);

		return $res;
	}

	/* Copy message
		 rfc2060 section 6.4.7
	 */
	function imapCopy ($imap_conn, $msgno, $tombox) {
		global $cmd_tag;

		$buff = 256;

		$cmd = "$cmd_tag COPY $msgno $tombox\r\n";

		$res = imapCmd ($imap_conn, $cmd, $buff);

		return;
	}

	/* Search message in the mbox
		 query syntax can be seen at rfc2060 section 6.4.4
	 */
	function imapSearch ($imap_conn, $query) {
		global $cmd_tag;

		$buff = 1024;

		$cmd = "$cmd_tag SEARCH $query \r\n";

		$res = imapCmd ($imap_conn, $cmd, $buff);

		return $res;
	}

	/* Create a mbox
		 query syntax can be seen at rfc2060 section 6.3.3
	 */
	function imapCreate ($imap_conn, $mbox) {
		global $cmd_tag;

		$buff = 256;

		$cmd = "$cmd_tag CREATE $mbox\r\n";

		$res = imapCmd ($imap_conn, $cmd, $buff);

		return;
	}
?>
Return current item: Jwapmail