#version Smart_Script 1.20
#timeout 1200
#linewait 0
#error_continue

// Outlook Express 5.0 Mail Downloading.ssc (MCHK Version) for Smart Script
// Copyright 1999,2000 Sony Corp.
// VASVersion=1.0.01.01110
function  main( $argc , @argv )
{
    $check = 0;
    if ( $argc == 1 ) {
        if ( @argv[ 0 ] eq "c" ) {
            //0x0002 Check by MAPI
            //0x0004 Check by normal exit
            //0x0008 Check by Filesize
            //0x0010 Don't Dialup before exec script
            exit 6;
        }
    }
    if ( $argc > 0 ) {
        $check = @argv[ 0 ];
    }
    if ( $argc == 2 ) {
        :$limit = @argv[ 1 ];
    } else {
        :$limit = 15;
    }
    Initialize(  );
    if ( $check == 2 ) {
        $before = ExecuteFileWait( :$EMCHKpath );
    }
    $_result = IsWindowExisting( :$WndNameMain , :$ClassNameMain );
    if ( ! $_result ) {
        $_result = IsFileExisting( :$path );
        if ( $_result ) {
            $_result = ExecuteFile( :$path );
        } else {
            $_result = TimerMessage( :$errmsgFileNotFound , 3 );
            exit 1;
        }
    }
    %express = WaitWindowOpen( :$WndNameMain , :$ClassNameMain , 30 );
    $_result = IsWindowValid( %express );
    if ( $_result ) {
        $_result = RestoreWindow( %express );
        $_result = SelectMenu( %express , :$IDReceive , "i" );
        %state = WaitWindowOpen( :$WndNameState , :$ClassNameDlg , 15 );
        $_result = IsWindowValid( %state );
        if ( $_result ) {
            $_result = SetTimer(  );
            $NotConnect = 0;
            $Error = 0;
            while( ! $NotConnect && ! $Error && GetTimer( ) < :$limit * 60 ) {
                $NotConnect = IsWindowExisting( :$WndNameNotConnected , :$ClassNameStatic );
                $Error = IsWindowExisting( :$WndNameError , :$ClassNameStatic );
            }
            if ( $NotConnect ) {
                if ( $check == 2 ) {
                    $_result = Sleep( 3 );
                    $after = ExecuteFileWait( :$EMCHKpath );
                    $result = MAPICheck( $before , $after );
                } else {
                    $result = 0;
                }
                exit $result;
            } else {
                if ( $Error ) {
                    $_result = TimerMessage( :$errmsgTaskError , 3 );
                } else {
                    $_result = TimerMessage( :$errmsgEnd , 3 );
                }
                exit 1;
            }
        } else {
            $_result = TimerMessage( :$errmsgStatusDlgNotFound , 3 );
            exit 1;
        }
    } else {
        $_result = TimerMessage( :$errmsgCantOpen , 3 );
        exit 1;
    }
}
//
function $ MAPICheck( $before , $after )
{
    if ( $before != -1 && $after != 1 ) {
        if ( $before < $after ) {
            return -1;
        } else {
            return 0;
        }
    } else {
        return 0;
    }
}
//
function  Initialize(  )
{
    :$path = LoadRegistry( "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Outlook Express\\" , "InstallRoot" );
    :$path &= "\\msimn.exe ";
    //Window
    :$WndNameMain = "*Outlook Express";
    :$ClassNameMain = "Outlook Express Browser Class";
    :$WndNameState = "Outlook Express";
    :$WndNameNotConnected = "Not Connected";
    :$WndNameError = "Some errors occurred while processing the requested tasks.  Please review the list of errors below for more details.";
    :$ClassNameDlg = "#32770";
    :$ClassNameStatic = "Static";
    //Menu ID
    :$IDReceive = 40197;
    //Error Messages
    :$errmsgFileNotFound = "msimn.exe not found.";
    :$errmsgEnd = "Terminated by timeout or by pressing cancel button.";
    :$errmsgStatusDlgNotFound = "Status Dialog not found.";
    :$errmsgCantOpen = "Outlook Express window can't open.";
    //for Mail Check
    :$EMCHKpath = "bin\\SEEMCHK.exe";
}
