#!/usr/bin/env python
""" Simple script showing how to use the python-mms library to decode a binary
MMS message file and display textual information about it.
This script does not actually dump the contents of binary data parts (such as
images and audio clips), but shows how it can be done.
@author: Francois Aucamp <faucamp@csir.co.za>
@license: GNU LGPL
"""
import sys
# import the python-mms library
import mms
if __name__ == '__main__':
if len(sys.argv) != 2:
print 'Usage: %s MMS_FILE' % sys.argv[0]
sys.exit(1)
# Decode the specified file
message = mms.MMSMessage.fromFile(sys.argv[1])
# Dump header information
print 'MMS header information:\n------------------------'
for hdr in message.headers:
value = message.headers[hdr]
if type(value) == tuple:
print '%s: %s' % (hdr, str(value[0]))
if len(value[1]) > 0:
parameters = value[1]
print ' parameters:'
for param in parameters:
print ' %s: %s' % (param, parameters[param])
else:
print '%s: %s' % (hdr, str(message.headers[hdr]))
# Dump message body information
print '\nMMS body information:\n----------------------'
print 'Number of pages in message: %d' % len(message.pages)
print 'Number of data parts in message: %d' % len(message.dataParts)
counter = 0
for part in message.dataParts:
counter += 1
print '\n Data part #%d\n ------------' % counter
for hdr in part.headers:
value = part.headers[hdr]
if type(value) == tuple:
print ' %s: %s' % (hdr, str(value[0]))
if len(value[1]) > 0:
parameters = value[1]
for param in parameters:
print ' %s: %s' % (param, parameters[param])
else:
print ' %s: %s' % (hdr, str(part.headers[hdr]))
print ' Data length: %d bytes' % len(part)
# In this exxample, we only print the data of text-based data parts
if part.contentType.startswith('text/'):
print ' Contents:'
print ' "%s"' % part.data