Path: lib/mms2r.rb
Last Update: Sun Dec 20 13:05:02 -0800 2009
Media MMS2R dot/f_1.png


MMS2R is a library to collect media files from MMS messages. MMS messages are multipart emails and mobile carriers often inject branding into these messages. MMS2R strips the advertising from an MMS leaving the actual user generated media.

The Tracker for MMS2R is located at Please submit bugs and feature requests using the Tracker.

If MMS from a carrier not known by MMS2R is encountered please submit a sample to the author for inclusion in this project.

Stand Alone Example

 require 'rubygems'
 require 'mms2r'
 mail = TMail::Mail.parse(IO.readlines("sample-MMS.file").join)
 mms =
 subject = mms.subject
 number = mms.number
 file = mms.default_media

Rails ActionMailer#receive w/ AttachmentFu Example

 def receive(mail)
   mms =
   picture = # picture is an attachemnt_fu model
   picture.title = mms.subject
   picture.uploaded_data = mms.default_media!

More Examples

See the README.txt file for more examples

Built In Configuration

A custom configuration can be created for processing the MMS from carriers that are not currently known by MMS2R. In the conf/ directory create a YAML file named by combining the domain name of the MMS sender plus a .yml extension. For instance the configuration of senders from AT&T’s cellular service with a Sender pattern of have a configuration named conf/

The YAML configuration contains a Hash with instructions for determining what is content generated by the user and what is content inserted by the carrier.

The root hash itself has two hashes under the keys ‘ignore’ and ‘transform’, and an array under the ‘number’ key. Each hash is itself keyed by mime-type. The value pointed to by the mime-type key is an array. The ignore arrays are first evaluated as a regular expressions and if the evaluation fails as a equality for a string filename. Ignores work by filename for the multi-part of the MMS that is being inspected. The array pointed to by the ‘number’ key represents an alternate mail header where the sender’s number can be found with a regular expression and replacement value for a gsub eval.

The transform arrays are themselves an array of two element arrays. The elements are parameters for gsub and will be evaluated from within the ruby code.

Ignore instructions are honored first then transform instructions. In the sample, masthead.jpg is ignored as a regular expression, and spacer.gif is ignored as a filename comparison. The transform has a match and a replacement, see the gsub documentation for more information about match and replace.

— ignore:

  - /^masthead.jpg$/i
  - spacer.gif
  - /\AThis message was sent using PIX-FLIX Messaging service from .*/m


  - - /\A(.+?)\s+This message was sent using PIX-FLIX Messaging .*/m
    - "\1"


  - from
  - /^([^\s]+)\s.*/
  - "\1"

Carriers often provide their services under many different domain names. The conf/aliases.yml is a YAML file with a hash that maps alternative or legacy carrier names to the most common name of their service. For example in terms of MMS2R is an alias for Therefore when an MMS with a Sender of is processed MMS2R will use the configuration to process the message.

Required files

rubygems   tmail/mail   fileutils   pathname   tmpdir   yaml   uuidtools