#!/usr/bin/expect -f

# IMAP4 Expect module for sawdog

set env(TERM) vt100

set timeout 8
match_max 100000

for {set x 0} {$x<3} {incr x} {
   spawn telnet $argv imap
   expect "Connection refused" {
      exit 2
   } "Escape character is '^\]'.\r\r" {
      expect "* OK" { 
         send -- "sawdog NOOP\r"
         expect "sawdog OK NOOP" {
	     exit 0
	 }
      }
   } 
   sleep 5
}
exit 1
