<?php
/*
This file is part of Thomas Bley's moregroupware webmail2/calendar2/admin2 module. (tb-mgw)

More information:
-----------------

Simple Groupware Solutions Thomas Bley
Fichtenstr. 23
Germany, 85640 Putzbrunn

Contact:
--------

info@simple-groupware.de

http://www.simple-groupware.de


Copyright 2002-2003 Thomas Bley
tb-mgw is distributed under the terms of the GNU General Public License 

tb-mgw is free software; 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.

tb-mgw 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 for more details.

You should have received a copy of the GNU General Public License
along with tb-mgw; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// Imap_trace
// Moregroupware.org

die;

function sqimap_session_id() {
    global $sqimap_session_id;
    return( sprintf("A%03d", $sqimap_session_id++) );
}

function execute_imap($command) {
  global $connection;

  $clrf = "\r\n";

  fputs($connection,sqimap_session_id()." ".$command.$clrf);

  $return = '';
  $line   = '';
  $loops  = 0;
/*
  while((strpos($return, $clrf) === FALSE OR substr($line,3,1) !== ' ') AND $loops < 100){
	  $line    = fgets($connection, 512);
	  $return .= $line;
	  $loops++;
	}
    
    echo $return."<br>";
*/
  echo fgets($connection, 512)."<br>";
}

  $hostname = "";
  $port = 143;
  
  $sqimap_session_id = 0;


  $connection = fsockopen($hostname, $port, $errno, $errstr, 5);
  echo fgets($connection, 1024)."<br>";

  execute_imap("LOGIN \"user1\" \"user1\"");
  execute_imap("select INBOX");
  execute_imap('EXAMINE "INBOX"');
  execute_imap('STATUS "INBOX" (UNSEEN)');

  fclose($connection);
?>