Email-based Dictionary Service #

Short version:

Want to look up words on the go? Send an email (from your cellphone, smartphone, Blackberry, pager, etc.) to dictionary [at] this site's domain with your word in either the subject or the body, and in return receive the word's definition. Low-tech (no SOAP, XML-RPC, WAP, WS, etc. here), and yet handy and It Just Works™. Want to run the script yourself? See dictionary.pl.

Long version:

I have wanted to look up words in locations where a dictionary is inaccessible often enough that I have decided to do something about it. My cellphone is usually within reach, and in theory always has signal (in practice, I may need to switch from T-Mobile to Verizon in order to make that assertion hold). Modern phones may have a WAP or even a web browser built-in (especially those of the smartphone variety), but that's not something I can rely on (neither do I relish having to do anything with WAP). However, almost all phones sold within the past two years (mine included) have some kind of SMS functionality, and usually by extension some form of email access (via an SMS or MMS gateway, if not an outright email client). The ideal solution is therefore to have a service listen to some email address, and upon receiving a message, have it return the definition(s) of the word(s) contained. This would be simple enough to implement and at the same time accessible by the most devices (Blackberry handhelds and two-way pagers included).

Leaving aside the "listening to an email address" part for the moment, we need to parse a received email, look up words, and send a message in return. Much in the same way that we approached the NNTP to RSS bridge, we will leverage existing Perl modules and only write some glue between them. Specifically, Mail::Internet and Mail::Header allow us to do the message parsing, while Net::Dict allows us to interface with RFC 2229-compliant dictionary servers. Specifically, we will use dict.org, which has access to eleven dictionaries, but any other server would work just as well. Since we're trying to minimize message size (SMS gateways have ~140 character limits), we only pick one definition to return (dictionaries are ranked in order of preference), and do some clean-up to strip out unnecessary whitespace. dictionary.pl is a Perl script that does all this plus some other clean-up (e.g. signature removal) and sanity checks.

Now we need to make it so that this script is invoked when a message at a specific address is received (with the contents of said email piped to it). This server happens to be running qmail, and so we can use a .qmail file for this. Specifically, I created the file .qmail-persistent:info-dictionary and within it I had the line |/fullpath/dictionary.pl (this discards the message after processing, but it is possible to add a second line with a mailbox path so that it would be received normally as well). Other email systems (sendmail, etc.) presumably have similar mechanisms, but I have not checked.

The net result is that I can now send email to dictionary [at] this site's domain and receive word definitions from wherever I am. An obvious extension would be to support SMS directly (thus broadening accessibility even more), but I'm not sure how exactly I'd approach that (there are free gateways for sending SMS, but receiving is seemingly trickier - I'd have to get a cellular modem presumably).

Apologies for having the email address as an image, but since I have gotten to the point of receiving 10,000+ spam email a week, I am forced to recourse to such extreme measures (the previously-observed decrease was very short-lived).

Post a Comment