#!/bin/bash
. findwine
WAITS="30"
$WINE "c:\\program files\\microsoft office\\office\\outlook.exe" /f $1 &>/dev/null
echo -n "Waiting $WAITS seconds for MAPI server to quit"
while [ true ]; do
  WAITS=$(($WAITS - 1))
  [ "$WAITS" = "0" ] && break
  echo -n "."
  sleep 1s
  ps axwww|grep -i "MAPISP32.EXE"|grep -v "grep -i MAPISP32.EXE" &>/dev/null
  [ "$?" != "0" ] && break
done
ps axwww|grep -i "MAPISP32.EXE"|grep -v "grep -i MAPISP32.EXE" &>/dev/null
if [ "$?" = "0" ]; then
  $DIALOG  --title "--- WARNING ---" --defaultno --yesno "The MAPI server process is still running.\nWe can kill it by killing all remaining wine processes." 7 60
  if [ "$?" = "0" ]; then
    wineserver -kill
    echo "wineserver killed"
  fi
fi
echo "done."
