Published: MMS2R PeepCode and Advanced Rails Recipes

Posted by Luke
on Friday, May 16

Two books that I worked on are now shipping!

Advanced Rails Recipes is now available in dead-tree form. I got my copy last week, and it’s quite useful. My recipe is on processing email with a daemon using the Fetcher. Check out Recipe 46 on page 257. Jon also wrote a recipe about background processing with Rails, which he will be speaking about at RailsConf. I don’t get a dime from the sales of this book, but autographed copies are available for a modest fee. ;-)

MMS2R: Making Email Useful is now available from PeepCode. I worked on this with the creator of MMS2R, Mike Mondragon and with the helpful editing of Geoffrey Grosenbach. This 60 page PDF is the most comprehensive documentation available on creating a Ruby application that interacts with email, and is only $9. So buy a copy, and buy a copy for your friends!

Seeking MMS sample data

Posted by Luke
on Monday, November 12

The MMS2R project is pushing forward to a 2.0 release that promises to be easier to use and more Ruby-like.

We want to make this the best MMS library in any language, and to do that we need your help.

We currently support the following carriers. If you don’t see your carrier on this list, please send an MMS message to me at luke@slantwisedesign.com and I’ll work on adding it to the library. We especially need European carriers.

  • Alltel
  • AT&T/Cingular
  • Dobson/Cellular One
  • Helio
  • Nextel
  • Orange (Poland)
  • Orange (France)
  • PXT (New Zealand)
  • Sprint
  • T-Mobile (USA)
  • Verizon

Using MMS2R for mobile integration with Rails

Posted by Luke
on Thursday, May 24

At Slantwise, we’ve been doing some projects that involve taking user-submitted content from cell phones. Using an MMS-to-email gateway, it’s straightforward to ingest photos and videos into a Rails application with ActionMailer. Every phone we’ve tested has the ability to send an MMS message to an email address, so this is a cheap and easy way to get started. We’d like to use a shortcode like Twitter’s 40404 some day, but they are hellaciously expensive.

While receiving the email is straightforward, you still have to deal with the advertising and general crap that is added to the messages by the phone carriers.

Here’s an example from Sprint, by far the worst carrier we’ve come across:

Sprint adds advertising and other garbage to your MMS message

Not only is this message stacked with ads and other nonsense, the worst part is that the photo isn’t actually included as an attachment! You have to download it from Sprint’s server.

Thankfully, we found the MMS2R library, created by Mike Mondragon. MMS2R greatly simplifies processing MMS messages. MMS2R removes advertising, eliminates default subjects, and makes fetching media from the message much easier. It even has a special case to download the real media for Sprint messages. MMS2R decodes and extracts files from multipart MIME email so you don’t have to!

Imagine you have a MediaItem model that has a title and a file associated with it (we used AttachmentFu to store the files). Here’s an ActionMailer you that will process an incoming MMS message and store it as a new MediaItem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'mms2r'
require 'mms2r/media'

class IncomingMmsHandler < ActionMailer::Base

  def receive(email)
    # create a new Media Item
    item = MediaItem.new
    
    begin
      # Parse the MMS attachments with MMS2R
      mms = MMS2R::Media.create(email)
      mms.process

      # Gets the subject, stripping out known carrier defaults
      item.title = mms.get_subject
    
      # Get the most likely media for the message
      # MMS2R mocks up a CGI.rb temp file object, 
      # so get_media can be used with AttachmentFu!
      item.uploaded_data = mms.get_media
    
      # persist the item
      item.save!
    ensure
      # clean up the temp files      
      mms.purge
    end
  end
end

The error handling in this example is rudimentary for simplicity’s sake.

This all works on a per-carrier basis. The currently supported carriers are:

  • AT&T/Cingular
  • Dobson/Cellular One
  • Nextel
  • Sprint
  • T-Mobile
  • Verizon

New rules have to be added to strip advertisements from unknown carriers (you’ll still be able to access the media). New carriers are easy to add, so don’t be shy about submitting a patch.

MMS2R is being used in production at several web sites including mymojobaby, Vedio.tv and our own project, which is still in private beta.

(This is a preview of some of what I’ll be speaking about at Ostrava on Rails. The speakers have just been posted and it looks like a great line up. Don’t miss it if you’re in Europe.)