Module MMS2R
In: lib/mms2r.rb
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.


parse   register  

Classes and Modules

Class MMS2R::Media


CARRIERS = {}   A hash of MMS2R processors keyed by MMS carrier domain.
EXT = { 'text/plain' => 'text', 'text/plain' => 'txt', 'text/html' => 'html', 'image/png' => 'png', 'image/gif' => 'gif', 'image/jpeg' => 'jpeg', 'image/jpeg' => 'jpg', 'video/quicktime' => 'mov', 'video/3gpp2' => '3g2' }   A hash of file extensions for common mime-types

Public Class methods

Simple convenience function to make it a one-liner: MMS2R.parse raw_mail or MMS2R.parse File.load(raw_mail) Combined w/ the method_missing delegation, this should behave as an enhanced TMail object, more or less.


# File lib/mms2r.rb, line 49
  def self.parse raw_mail
    mail = TMail::Mail.parse raw_mail

Registers a class as a processor for a MMS domain. Should only be used in special cases such as MMS2R::Media::Sprint for ‘‘


# File lib/mms2r.rb, line 18
  def self.register(domain, processor_class)
    MMS2R::CARRIERS[domain] = processor_class