help, they are stealing my outlook webmail

I work for a company that uses Exchange for its internal email. This means I have to use Outlook Web Access to access my account there, since I am 100% remote, and Entourage doesn’t work over our VPN.

update

WebOutlook 0.3 released, with DELE support, and a bugfix. Download here.

to gmail!

Wouldn’t it be nice if we could scrape this in some way, and perhaps publish it with a regular POP server? Then Gmail could access it and merge it with our other accounts.

Thankfully, Adrian Holovaty1 has written WebOutlook, a Python script to do just that. Except, it doesn’t support Gmail because the UIDL command isn’t implemented. Also it doesn’t support the HTTP Basic Authentication Scheme, which is how my particular OWA server authenticates me. Also, it deletes your mail without asking. Ok…

open-source ftw

After a few hours of reading RFC 1939 and struggling with Python’s combinatorics of tuples, dicts, and primitives, I am pleased to release WebOutlook 0.2, which you can download here. (GPL’ed because the original version is GPL’ed.)

Requirements:

  • Python 2.4
  • A web server (I’m actually using my local machine with a static IP)
  • A Gmail account

Installation:

  • Set your Exchange server in popdaemon.py
  • Run python2.4 popdaemon.py
  • Log in to Gmail, and go to “Settings”, “Accounts”, “Get mail from other accounts”
  • Add a new account
    • Check “Leave mail on server”
    • Add a tag so you know where the messages came from

Now, watch as Google logs into your crappy local Python script and steals your mail out of your own house.

todo list

I welcome patches, and can give you subversion access if necessary. The following things need to be done:

  • Make the authentication mode configurable
  • Add support for sending mail
  • Add support for folders other than the inbox

code example

I had to write this thing in Python:

import re
re.search(r"Message-ID: <(.*?)>", msg, re.S).group(1)

In Ruby I would have written:

msg[/Message-ID: <(.*?)>/, 1]

Or in POP:

REGX Message-ID: <(.*?)>
STRG msg
GETG 0
.
+OK
.

Just kidding about the POP. But I’m not really seeing the benefit of Python here, even with the shortcuts (r instead of re.compile, re.S instead of re.DOTALL).

notes

[1] Best known for playing the MacGyver theme song on acoustic guitar.

9 responses

  1. The particular college in the university I used to work for uses MS Exchange as well. Since the tech department apparently refused to do anything after hours, maintenance, reboots and “updates” would happen promptly at 4:55pm. This was pretty much a daily thing. Drove the staff and faculty fucking nuts (still does I’m sure).

  2. Just FYI, the r'...' syntax is not a shortcut for re.compile. It creates a raw string, which means escape sequences are included verbatim, which is convenient for regular expressions.

    See http://docs.python.org/ref/strings.html, especially:

    “String literals may optionally be prefixed with a letter r or R; such strings are called raw strings and use different rules for interpreting backslash escape sequences.”

    and

    “When an r or R prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string. For example, the string literal r"\n" consists of two characters: a backslash and a lowercase n.”

  3. I wrote a gem called RExchange a long time ago that lets you pull mail from Exchange via WebDAV. Sam Smoot fixed stuff and I think a few others have contributed to it, so I have no idea what its current state is, but you might be able to use it somehow.

  4. Wow, you are awesome… I’d found Adrian’s script a few days ago and hadn’t had luck with getting it to work, but yours allowed me to download my exchange email into Apple’s Mail.app (connecting to the localhost POP server) on the first try! Just need to figure out a way to get my “read” email deleted from the Exchange server without having to log into OWA periodically.

    Anyway, well done! A number of readers at the Macintouch.com website have been searching for a way to get their Exchange email into Mail.app for servers that won’t allow IMAP, and I’m going to point them to your code!

  5. Thanks!

    Actually, with version 0.3 (above), you can choose whether to leave the mail on the server or not, and it will work.