Run an IMAP Tickler file via a Cron script

Zak Greant’s AppleScript for running a Tickler file (a filing system for future actions that is part of the “Getting Things Done” (GTD) system) is very clever.

But it does have one small drawback for some people. Its mailboxes are stored in your Local Folders. If you use more than one Mac to assess a central IMAP store of emails, you will only have your Tickler file on one of the Macs.

One way around this is to run a Tickler file with MailTags. Although due to the way that Mail.app handles IMAP support, a mailbox rebuild will refresh your local cache and wipe out the MailTags info, which is appended to the cached copy of each emlx file.

Ted Pavlic has found another work-around for this which he posted in the comments on the GTD AppleScript post.

He runs a centralised Tickler file on his IMAP server using this script in a cronjob:

#!/bin/sh

# NOTE: The mailutil below has had the maildir patch applied.

# Set things to eastern time zone to keep things in sync
export TZ=EST5EDT

# Get the valid strings
DAY=`date +%d`
WEEK=`echo “($DAY – 1)/7 + 1″|bc`

# On the first day of the month, push monthly notes into inbox
if [ "$DAY" == "01" ]; then
THISMONTH=`date +%m-%b`
/home/tedpavlic/bin/mailutil appenddelete “/home/tedpavlic/.imap/.@TICKLER.Month.$THISMONTH/” “/home/tedpavlic/.imap/.@INBOX/”
fi

# On every day, push dailies
/home/tedpavlic/bin/mailutil appenddelete “/home/tedpavlic/.imap/.@TICKLER.Week$WEEK.$DAY/” “/home/tedpavlic/.imap/.@INBOX/”

Similar Posts:

Tags: , , , , , , , , ,

3 Responses to “Run an IMAP Tickler file via a Cron script”

  1. Ted Pavlic says:

    It’s worth nothing that that script should be run nightly just after midnight. It copies the CURRENT day’s contents (and month if the current day is “01″) into the inbox.

    Because my IMAP server is on GMT time, I set my cronjob to run at 5:01AM GMT every night. That corresponds to 12:01AM for eastern standard time and 1:01AM for eastern DST. That’s fine with me.

    Also note that I use mailutil to do the message shuffling. mailutil is made by the same people who make pine. There is a non-standard patch that they release for the most recent versions of pine and mailutil that supports the maildir mailbox format (which uses a hashed directory structure). That patch is available at:

    http://www.math.washington.edu/~chappa/pine/info/maildir.html

    If your server uses a simpler type of mailbox, you might be able to get away with just concatenating one mailbox onto the other. In that case, you won’t need mailutil at all (however, note that mailutil is a very general utility. You can use it to transfer messages from basically any mailbox format to any other mailbox format. It can even connect to remote mailboxes and let you shuffle messages from here to there. It does everything that any IMAP client can do (and more)).

  2. Ted Pavlic says:

    Here’s another goody. A procmail script that will automatically file your ticklers based on a key in the subject.

    The idea is that you e-mail yourself a message with a subject starting with “tickle##” where ## is a number from 01 (can be 1 as well) to 31 and procmail will automatically file it AND mark it read in your tickler folders on your IMAP server. You then use my cronjob above to move those into your inbox on the appropriate day.

    =====
    :0
    * ^Subject:[ \t]*\/tickle([0-9]|[0-9][0-9]):.*
    {
    # Grab the string that brought us here
    TICKLE=$MATCH

    # If it was a single-digit day, grab it and pad it with a 0
    :0
    * TICKLE ?? ^tickle\/[0-9]:
    * MATCH ?? ()\/[^:]+
    { TICKLEDAY=”0$MATCH” }

    # Otherwise grab the two-digit day
    :0
    * TICKLE ?? ^tickle\/[0-9][0-9]
    { TICKLEDAY=$MATCH }

    # Calculate the week using bc
    TICKLEWEEK=”`echo \”($TICKLEDAY – 1)/7 + 1\”|bc`”

    # Grab the subject that came after the tickle header
    :0
    * TICKLE ?? ^tickle([0-9]|[0-9][0-9]):\/.*
    { TICKLESUBJECT=$MATCH }

    # Make a note in header showing that this rule ran
    :0 f
    | ${FORMAIL} -A”X-MyProcmailRC: GTD Handler caught TICKLER (White listed)”

    # Update the subject to just have “tickler” up front. If you want to refile it later,
    # just move the message. Notice that -i is used, so the old subject will be saved to
    # Old-Subject: in the header
    :0 f
    | ${FORMAIL} -i”Subject: tickler:$TICKLESUBJECT”

    # Move the message to appropriate tickler folder for this day
    :0 wc
    “$MAILDIR/.@TICKLER.Week$TICKLEWEEK.$TICKLEDAY/”

    # Mark it read
    :0 A hi
    | mv “$LASTFOLDER” “$LASTFOLDER:2,S”
    }
    =====

    If you cut out a lot of the stuff in the middle that does the tickler stuff, then you can use this as a template for more auto-filing stuff.

    For example, I have a rule that routes messages with subjects starting with “todo:” or “defer:” to a DEFER folder of mine and those starting with “action:” to an ACTION folder.

  3. Ted Pavlic says:

    I should mention that there are other ways to mark messages read. The method I used is just consistent with the Maildir folders on my Courier IMAP server. If you don’t use Maildirs, you could use formail to with the -A switch and the header “X-Status: 0″ (I think I remember correctly; try it and see).

Leave a Reply