#!/bin/bash

tag=mail

layout='(split vertical:0.200000:0 (clients horizontal:0) (clients max:0))'

# create layout skeleton
herbstclient load "$tag" "$layout"

# close all existing windows created by this script gracefully
ids=( $(xdotool search --classname 'specialtag9(mutt|fetchmail|procmaillog)') )
for i in ${ids[@]} ; do
    echo close $i
    herbstclient close "$i"
done

# some terminal for fetchmail output
{
    herbstclient rule maxage=60 tag=$tag pid=$BASHPID once index=0
    exec urxvt -name specialtag9fetchmail -title fetchmail -e fetchmail --idle
} &

# monitor procmail.log to see subject and destination folder of new mails
{
    herbstclient rule maxage=60 tag=$tag pid=$BASHPID once index=0
    exec urxvt -name specialtag9procmaillog -title procmail.log -e tail -f ~/procmail.log
} &

# launch mutt in the main area, which is in max layout, so you viewing
# attachments with external applications is fun
herbstclient rule maxage=60 tag=$tag pid=$$ index=1 once
exec urxvt -name specialtag9mutt -title mutt -e mutt


