#!/bin/bash
# $Id: sbc_find_imap,v 1.2 2010/04/26 07:33:40 sesam Exp $
read_ini()
  {
    SM_INI=`grep -i '^sm_ini=' /etc/sesam2000.ini|cut -d"=" -f2`
    echo `grep -i "$1=" "$SM_INI"|cut -d"=" -f2`
  }


select_level() {
SWITCH=`echo $LEVEL|cut -b1`
case  $SWITCH in
         [fF]) LEVEL=full;
             ;;
         [dD]) LEVEL=diff;
               if [ -r ${DORIFILE}.D ]
                  then
                    FIND_TIME=" -cnewer ${DORIFILE}.D ";
                  else
                     echo `date +"%Y-%m-%d %T:"`" sbc-2059: Warning:  No timestamp file found. Doing full save" >&2
                  fi
             ;;
         [iI]) LEVEL=incr;
               if [ -r ${DORIFILE}.I ]
                  then
                    FIND_TIME=" -cnewer ${DORIFILE}.I ";
                  else
                     echo `date +"%Y-%m-%d %T:"`" sbc-2059: Warning:  No timestamp file found. Doing full save" >&2
                  fi
             ;;
         [cC]) LEVEL=copy;
             ;;
esac
LEVEL=${LEVEL:-copy}
}
# end of select_level()





shift
while getopts ba:l:O:o:i:j:t:f:d:S:s:v:P:T:X:x:n:L:C:F:V:A opt
    do
          case $opt in
             a) BACKUPTYPE=$OPTARG;;
             l) LEVEL=$OPTARG;;
             j) JOBNAME=$OPTARG;;
             X) EXCLUDE_FILE=$OPTARG;;
             x) EXCLUDE_LIST=$OPTARG;;
             f) FILE_LIST=$OPTARG;;
             T) TIMESTAMP=$OPTARG;;
             S) x=$OPTARG;;
             s) SSID=$OPTARG;;
             d) x=$OPTARG;;
             v) x=$OPTARG;;
             s) x=$OPTARG;;
             t) x=$OPTARG;;
             i) x=$OPTARG;;
             L) x=$OPTARG;;
             C) x=$OPTARG;;
             O) x=$OPTARG;;
             o) x=$OPTARG;;
             F) x=$OPTARG;;
             \?) usage
                exit 1;;

          esac
    done
    shift `expr $OPTIND - 1`

    BACKSRC=$*
    MAILDIR=$1

gv_ro_bin=`read_ini gv_ro_bin`
gv_rw_tmp=`read_ini gv_rw_tmp`
gv_rw_times=`read_ini gv_rw_times`
DORIFILE=${gv_rw_times}/${JOBNAME}

select_level




cd /
# touch timestamp every time to avoid error bcs. of missing -newer "file" 
touch ${gv_rw_tmp}/slx_imap_${SSID}.ts 
set -x
  find $BACKSRC -name "cyrus*NEW" -prune -o -regex ".*/var/lib/cyrus/proc" -prune -o -regex "${MAILDIR}" -exec touch ${gv_rw_tmp}/slx_imap_${SSID}.ts \; -regex "${MAILDIR}/.*/[0-9]*\.$"  -newer ${gv_rw_tmp}/slx_imap_${SSID}.ts -exec echo newmail: {} \;  -o -regex "${MAILDIR}/.*/[0-9]*\.$" ${FIND_TIME} -exec ${gv_ro_bin}/sbc_imap_subject {} \;  -print -o -print

