Mutt to Google Calendar Script

I did a bit of work on integrating mutt and ics invites with google calendar using a python script found here at ub3rgeek.net. The google calendar apis are really easy to use and the gdata python library is excellent.

The original script auto-accepted the invite and uploaded it to google calendar when viewed in mutt.

I added some additional functionality to the script:

The script will print out the invite inline (if the mailcap is set to do so). When the attachment is actually viewed, it will perform additional checks to see if the event already exists in your calendar, if there are conflicts, and then prompts you as to whether you want to accept, reject, update, etc.

If the event is accepted, the id, status, and google id are saved to a local database.

Here’s the code:

This was cobbled together with help from gdata API documentation found http://code.google.com/apis/calendar/developers_guide_python.html.

This script requires:
gdata python bindings
atom python module
vobject python module
Google Calendar account

To setup:
Add the following to your .mailcap and then you can simply exec the attachment
and it will get added to your google calendar.

Create the directory ~/.gcal because the local data store used by the script is saved there.

You may now use a configuration file to setup your username, password and calendar. NOTE this is not actually any more secure than using the command line in your .mailcap configuration file assuming sane permissions.

In ~/.gcal/ics-gcal.conf you may specify the following tokens:

If the command line has these options specified they will OVERRIDE the config file. None are required as long as between the config file and the command line all required options are set.

Calendar name can be found on the calendar details page, or based
on your calendar’s xml/ical links.

If your XML link is:
http://www.google.com/calendar/feeds/yourname@gmail.com/public/basic
then your calendar name is yourname@gmail.com

You will probably want/need to set PYTHONIOENCODING to something, like utf_8. This will make sure the print statements work properly when people insert weird shit
in their descriptions. This seems to be the only env variable python uses when sending output to a pipe, which this script does when used with mutt

To use:

When you view an email with an ics invite in mutt, the invite will be parsed and displayed. You can then view the attachment to process it. The script will check a local store to see if this invite was already processed, will check your google calendar for conflicts, and then will prompt you for what to do.

If the event has a reminder set it will set a reminder using your default method for 30 minutes prior to the event. You can also override the default reminder with -r and -R.

3 Comments

    1. The script itself doesn’t, but I believe google calendar does (which actually annoys me quite a bit because there’s no way to disable that…)

  1. I found a few missing steps for setup if you want to use the script only to show text/calendar entries.

    1) If you get the error below, it probably means your copy of the python script does not have the correct indentation because you cut-and-pasted it from the text above. Click “Expand” tool and re-copy it.
    $ export PYTHONIOENCODING=utf=8
    $ ~/.mutt/ics-gcal.py -h
    File “/home/test/.mutt/ics-gcal.py”, line 33
    “””Print usage statement
    ^
    SyntaxError: invalid syntax

    2) missing module “python-tz”
    $ ~/.mutt/ics-gcal.py -h
    Traceback (most recent call last):
    File “/home/test/.mutt/ics-gcal.py”, line 64, in
    import pytz
    ImportError: No module named pytz

    $ apt-get install python-tz

    3) Minimum set of command-line arguments

    $ ~/.mutt/ics-gcal.py -o -f ./test.vcal
    You did not specify the required arguments (username, password, and file)

    Usage: /home/test/.mutt/ics-gcal.py [-hRo] [-c calendar] [-f file] [-p password] [-r minutes] [-u username]
    Take a vcalendar stream from a file and insert to it into a Google
    calendar

    Arguments:
    -c – Which calendar to upload to, default = ‘default’
    -f – ics file for input
    -h – Show Usage and exit.
    -p – Google Calendar password
    -r – Number of minutes for reminder length, default = 30
    -R – Force adding a reminder even if the ics does not have
    an alarm set.
    -u – Google Calendar username
    -o – Just print the calendar information

    You must specify a null username and null password:

    $ ~/.mutt/ics-gcal.py -o -f ./test.vcal -u null -p null

    4) Missing timezone

    $ ~/.mutt/ics-gcal.py -o -f ./test.vcal -u null -p null
    Traceback (most recent call last):
    File “/home/test/.mutt/ics-gcal.py”, line 499, in
    sys.exit(Main(sys.argv[1:]))
    File “/home/test/.mutt/ics-gcal.py”, line 491, in Main
    printCalendar(ics)
    File “/home/test/.mutt/ics-gcal.py”, line 115, in printCalendar
    tz = timezone(os.environ[‘TZ’])
    File “/usr/lib/python2.7/UserDict.py”, line 23, in __getitem__
    raise KeyError(key)
    KeyError: ‘TZ’

    You must specify your timezone using the TZ environment variable, e.g.

    $ export TZ=GMT+10
    for GMT+10 hours

    5) Working!

    $ ~/.mutt/ics-gcal.py -o -f ./test.vcal -u null -p null
    Calendar Event
    ————–
    Summary: text here
    Organizer: text here
    Start time: 00:00
    End time: 01:00
    Location: text here
    Description: text here

    6) From standard input?

    $ cat file.vcal | ~/.mutt/ics-gcal.py -o -f /dev/stdin -u null -p null

    Calendar Event
    ————–
    Summary: text here
    Organizer: text here
    Start time: 00:00
    End time: 01:00
    Location: text here
    Description: text here

Leave a Reply

Your email address will not be published. Required fields are marked *