Scripting Kolab Calendar Interactions

As mentioned previously, I would like to be able to do spreadsheet like calculations on my Kolab groupware calendar. Here is how I’m currently attempting that. There were a couple challenges that made this take longer than I had hoped. The first was making sure that, given two processes communicating via a pipe, closing the upstream process didn’t prematurely end the downstream process. This is what the funny redirection is for. The second issue that caused me grief was the carriage return character echo -en '\x0d', present in IMAP results. It caused bash -x output to be really confusing. An extra operation while sed’ing took care of it.

#!/bin/bash -x


rm -f out result
mkfifo out result

  echo "1 login ${username} ${password}"
  echo '2 select Cashflow'
  echo "3 search sentsince ${lastsunday}"
  echo '4 logout'
  sed -nr '/^\* search.*/I {
             s/^\* search +//I
             s/ *\r$//
             s/ /,/g
           }' out > result
) | openssl s_client -starttls imap -connect &> out &

msgs="$(cat result)"

  echo "1 login ${username} ${password}"
  echo '2 select Cashflow'
  echo "3 fetch ${msgs} body[2]"
  echo '4 logout'
  cat out > result
) | openssl s_client -starttls imap -connect &> out &

cat result

#do math
#use imap append command to create new (or what else to modify?) entry

Next steps are to use string processing (probably sed) utilities to extract the icalendar XML and xmlstarlet to parse it (beware the namespace).

Cashflow Calendar

My wife and I recently regained sufficient interest in tracking and projecting our personal finances. One of the questions we wanted to be able to answer was how much money would we have each day for the next month or so. We receive direct deposited salaries every week or two, but we also have some irregular income like the employee stock purchase plan that my company offers and I participate in. So we made a cashflow calendar. Using a Google Docs spreadsheet, we put days of the week as column headers, allowed seven rows for transactions, and calculated a daily total and a running sum at the bottom. I used conditional formatting to highlight when the checking account would dip below a threshold.

Screenshot from 2015-02-14 08:09:22

I like this because at least within the time period you’re writing up, you can track cashflow that has happened and project cashflow you expect to happen at the natural frequencies. You don’t have to divide a once-a-month bill in half to fit into a 2 week budget or in fourths to fit in a weekly budget. The cashflow calendar seems like an obvious tool, and indeed it is a slight evolution of what I was taught in Engineering Economy at Virginia Tech, but it wasn’t how the Financial Peace University budget template was formatted, and we had been coasting off of that class and its methods for some time.

At the moment we’re only really tracking out checking account and doing it all manually. I hope that with some clever scripting I may be able to have my computer handle the data entry automatically, and all I have to do is predict the future.