dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

dmc-mdir (1673B)


      1 #!/bin/sh
      2 # dmc - dynamic mail client
      3 # See LICENSE file for copyright and license details.
      4 # TODO: rewrite in C
      5 
      6 MD=$1
      7 if [ -z "${MD}" ]; then
      8   echo "Usage: dmc-mdir [Maildir-path]"
      9   exit 1
     10 fi
     11 
     12 mdir_ls () {
     13   echo "cur $(ls $1/cur | wc -l)" > /dev/stderr
     14   echo "new $(ls $1/new | wc -l)" > /dev/stderr
     15   echo "tmp $(ls $1/tmp | wc -l)" > /dev/stderr
     16 }
     17 
     18 dir=/
     19 folder=""
     20 while : ; do
     21   read A
     22   arg0=`echo $A | cut -d ' ' -f 1`
     23   arg1=`echo $A | cut -d ' ' -f 2-`
     24   case $arg0 in
     25   "ls")
     26     mdir_ls $MD/$dir
     27     echo "### 1 ls"
     28     ;;
     29   "lsd")
     30     ( cd $MD/$dir ; ls -d .??* | cat ) > /dev/stderr
     31     echo "### 1 lsd"
     32     ;;
     33   "cat")
     34     fold=`echo $arg1|cut -d / -f 1`
     35     arg1=`echo $arg1|cut -d / -f 2`
     36     if [ -z "$arg1" ]; then
     37       echo "### 0 cat Usage cat [cur|new|tmp]/[mail-index]"
     38     else
     39       file=$(ls $MD/$dir/$fold | head -n $arg1 | tail -n 1)
     40       file="$MD/$dir/$fold/$file"
     41       if [ -f "$file" ]; then
     42         cat $file > /dev/stderr
     43         echo "### 1 cat"
     44       else
     45         echo "### 0 cat No such file '$file'"
     46       fi
     47     fi
     48     ;;
     49   "head")
     50     dmc-hdr : < $(ls $MD/$dir/tmp | head -n $arg1 | tail -n 1) > /dev/stderr
     51     echo "### 1 head" 
     52     ;;
     53   "rm")
     54     file=$(ls $MD/$dir | head -n $arg1 | tail -n 1)
     55     if [ -f "$file" ]; then
     56       rm -f $file
     57       echo "### 1 rm"
     58     else
     59       echo "### 0 rm No such file"
     60     fi
     61     ;;
     62   "pwd")
     63     echo $dir > /dev/stderr
     64     echo "### 1 pwd $dir"
     65     ;;
     66   "login")
     67     # ignore
     68     echo "### 1 login Successful"
     69     ;;
     70   "exit")
     71     echo "### 1 exit ciao ciao"
     72     exit 0
     73     ;;
     74   "cd")
     75     dir=$arg1
     76     ;;
     77   *)
     78     echo "Usage: ls lsd cat head rm cd pwd login exit"
     79     ;;
     80   esac
     81 done