Giter VIP home page Giter VIP logo

python-messaging's Introduction

What is python-messaging?
=========================

A SMS/MMS encoder/decoder written 100% in Python.

History
=======

Originally written by Paul Hardwick with some bits from Dave Berkeley's
pysms. It was imported in the Wader and MobileManager projects and quickly
became clear that a joint effort would be more beneficial for everyone.

In 2010, the superb python-mms package by Francois Aucamp was merged into
python-messaging to provide a complete SMS/MMS encoder/decoder.

In 2011, as part of a license clarification, Francis Aucamp was contacted
and asked if it were possible to relicence his MMS portions as GPLv2, he
responded:
"feel free to re-license the parts of the python-mms code you are using in
your python-messaging project to GPL v2; you have my full consent."

SMS Features
============

 * Supports 7bit, 8bit and UCS2 encodings
 * Multipart encoding/decoding
 * Status report encoding/decoding
 * Relative validity
 * Alphanumeric address decoding
 * Supports python 2.5 up to 3.2
 * Tests


MMS Features
============

 * SMIL support
 * Main formats supported: jpg, gif, arm, 3gp, midi, etc.
 * Supports MMS 1.0-1.4 decoding/encoding
 * Supports python 2.5 up to 3.2
 * Tests

python-messaging's People

Contributors

andrewbird avatar mikaelhg avatar pmarti avatar thijstriemstra avatar zoltanszekely avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-messaging's Issues

copyright in LICENSE file

There is a line that reads:

Copyright (C) 2008-2010 python-messaging developers

Typically, you would use that format for a formal legal entity, such as a company or some other group that has legal status.

I recommend you update that line to individually name the developers who have contributed code.

Thanks.

message with smiles

Hello,

#!/usr/bin/env python

-- coding: utf-8 --

import os
import messaging
from messaging import sms
from messaging.sms import gsm0338
from messaging.sms import SmsSubmit

file = open('/var/spool/asterisk/sms_temp/gsm_sms_out/m_body.txt')
m_body = file.read()
file.close()

file = open('/var/spool/asterisk/sms_temp/gsm_sms_out/m_to.txt')
m_to = file.read()
file.close()

sms = SmsSubmit(m_to, m_body.decode('UTF-8'))

for pdu in sms.to_pdu():
pdu_out = str(pdu.pdu)
send_pdu_cmd="asterisk -rx " + "'dongle pdu COSMOTE " + pdu_out + "'"
os.system(send_pdu_cmd)

exit()

The above code is for sending sms messages with Asterisk and chan_dongle. It works well in general, but i found that if the message includes smiles it ends with : "ValueError: chr() arg not in range(256)"!

For example if the m_body.txt is "Δοκιμή!" the script runs without error.

If the m_body.txt is "Δοκιμή!Smile" it gives :

":~# /var/lib/asterisk/agi-bin/PDU_out.py
Traceback (most recent call last):
File "/var/lib/asterisk/agi-bin/PDU_out.py", line 25, in
for pdu in sms.to_pdu():
File "/usr/lib/python2.7/dist-packages/messaging/sms/submit.py", line 83, in to_pdu
sms_msg_pdu = self._get_msg_pdu()
File "/usr/lib/python2.7/dist-packages/messaging/sms/submit.py", line 258, in _get_msg_pdu
message_pdu = [pack_8bits_to_ucs2(self.text)]
File "/usr/lib/python2.7/dist-packages/messaging/utils.py", line 166, in pack_8bits_to_ucs2
nmesg += chr(ord(n) >> 8) + chr(ord(n) & 0xFF)
ValueError: chr() arg not in range(256)"

How can i solve this?
Thank u!

TypeError: int() can't convert non-string with explicit base

Hi

I am getting this error when decoding a PDU:

File "/usr/lib/python2.5/site-packages/python_messaging-0.5.10-py2.5.egg/messaging/utils.py", line 55, in to_array
return array('B', [int(pdu[i:i + 2], 16) for i in range(0, len(pdu), 2)])

Any ideas?

Cheers

MMS : no Unicode support in MMSMessagePage

When you try calling add_text on an MMSMessagePage instance with the argument as unicode, it rejects! Below are the lines of concern in mms/message.py :

         if not isinstance(text, str):
             raise TypeError("Text must be a string")

Possible error generating SmsSubmit PDU

Do you see any reason why this PDU generated by python-messaging:

079144872090025311000C914417325476980000FF0FF37219947FD7416937280603E101

Would give the error:

CMS ERROR: 304 (Invalid PDU mode parameter)

While this PDU generated by another program:

079144872090025311000C914417325476980000FF10F37219947FD7416937280603E141

Would succeed?

Both PDUs are the same length and appear to contain the same message according to various online decoders, but the working PDU has a UDL that is 1 longer and the last octet is different.

I am unsure whether this is a bug in SmsSubmit or in the device.

Greek GSM chars to PDU example

Hallo,
I can successfully decode greek-english PDU streams, but i can't encode greek text - all cups, to a readable PDU .

Can someone please show me a way to encode greek text to GSM and then to PDU?

Thank u!

email addresses in test_sms.py?

Hello,

It was pointed out to me that there are several email addresses in test_sms.py, such as the @tomslot.com address.

I don't think the tests send email, so there shouldn't be danger of that person suddenly receiving lots of spam. However, does that address need to be valid? Would it be ok to introduce a fake address in there?

I ask because I'm in the process of packaging python-messaging for debian, and I have enabled the tests to run during package build time. Last thing we want is for debian to be spamming innocent people. :)

Thanks.

How send MMS from Modem Dongle USB?

I ask how send MMS from this devices. I have Huawei E173 and Huawei E3131-s2. I use this devices with Raspberry Pi and PC with Linux. Please help me.

Thanks!

error: invalid command 'bdist_egg'

Caused when trying to run python setup.py install or pip install -e git+<gh clone url>. Seems to be caused by distribute_setup.py trying to reinstall the setuptools egg for some reason, simply commenting out the first two lines of setup.py fixed it for me.

Add tests for 7bit latin-1 encoding

This area was slightly broken until recently due to our lack of unittests in this area. Having some unittests that explicitly target 7bit decoding (and not the rest of the PDU toolchain) would be very nice.

utf-8' codec can't decode byte 0xff in position 0

Hello, I try to use python-messaging. I try your example for the encoding of a MMS text + photo, but here is the error message:

pi@raspberrypi:~/PycharmProjects/mms $ python3 mms.py
Traceback (most recent call last):
File "mms.py", line 13, in
payload = mms.encode()
File "/usr/local/lib/python3.4/dist-packages/python_messaging-0.5.12-py3.4.egg/messaging/mms/message.py", line 223, in encode
File "/usr/local/lib/python3.4/dist-packages/python_messaging-0.5.12-py3.4.egg/messaging/mms/mms_pdu.py", line 607, in encode
File "/usr/local/lib/python3.4/dist-packages/python_messaging-0.5.12-py3.4.egg/messaging/mms/mms_pdu.py", line 802, in encode_message_body
File "/usr/local/lib/python3.4/dist-packages/python_messaging-0.5.12-py3.4.egg/messaging/mms/message.py", line 552, in data
File "/usr/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

You could explain me how to take out there.
Thank you for your help
best regards
christophe

Concatenating multi-part PDU

Hello,

First I want to thank you for the awesome lib! I try to get PDUs for a long message and send them to my phone to test, and I discovered that a phone doesn't concatenate them back into one SMS.

I just do SmsSubmit('123456', 'some ... very ... long .... text').to_pdu() and send these parts to my GSM gateway.

What could be wrong?

TIA,
Philipp

We should decode generic WAP pushes

We should be able to decode generic WAP pushes so that we can test the content type properly. Currently we assume that all WAP pushes are MMS notifications, which obviously isn't true.

decode multipart pdu message

How can I achieve this goal?
I'm able to decode single pdu parts but how to put together?

Many thanks in advice and best regards.

Multipart SMS with Huawei e220

Hi everyone,

I failed to send a multipart SMS. Is that a still supported feature ?
I did :

import serial
from messaging.sms import SmsSubmit

sms = SmsSubmit("+44123231231", "hey " * 50)
ser = serial.Serial('/dev/ttyUSB1', timeout=1)
for pdu in sms.to_pdu():
    ser.write('AT+CMGS=%d\r' % pdu.length)
    ser.write('%s\x1a' % pdu.pdu)

Please publish to Pypi?

It'd be useful to have this package available on Pypi for easier installation with pip and to make it less reliant on this repository being available on GitHub on this URL.

Setting (relative) sms.validity causes TypeError

Hi,

I downloaded the latest version of python-messaging with sudo apt-get install python-messaging
I also built the documentation using the pmarti git-hub repository and tried the sample code. However, I get an error.
Below is the complete trace. I am on Ubuntu 12.04

Any ideas?

amil@amil-ubuntu:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import timedelta
>>> from messaging.sms import SmsSubmit
>>> 
>>> sms = SmsSubmit("+44123231231", "this SMS will auto-destroy in 5 hours")
>>> sms.validity = timedelta(hours=5)
>>> pdu = sms.to_pdu()[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/python_messaging-0.5.10-py2.7.egg/messaging/sms/submit.py", line 83, in to_pdu
    sms_msg_pdu = self._get_msg_pdu()
  File "/usr/local/lib/python2.7/dist-packages/python_messaging-0.5.10-py2.7.egg/messaging/sms/submit.py", line 235, in _get_msg_pdu
    msgvp_pdu = encode_str(chr(msgvp))
TypeError: integer argument expected, got float
>>> 

TypeError: super() argument 1 must be type, not classobj

Hello,

I'm trying to create an MMS Smile using the providing example but i have the followings errors

Python 2.7 :
File "test_mms.py", line 9, in
slide1.add_image('/home/nickilo/image1.jpg')
File "/usr/local/lib/python2.7/dist-packages/messaging/mms/message.py", line 341, in add_image
self.image = (DataPart(filename), time_begin, time_end)
File "/usr/local/lib/python2.7/dist-packages/messaging/mms/message.py", line 452, in init
super(DataPart, self).init()
TypeError: super() argument 1 must be type, not classobj

Python 3.5
File "test_mms.py", line 14, in
payload = mms.encode()
File "/usr/local/lib/python3.5/dist-packages/messaging/mms/message.py", line 223, in encode
return encoder.encode(self)
File "/usr/local/lib/python3.5/dist-packages/messaging/mms/mms_pdu.py", line 607, in encode
msg_data.extend(self.encode_message_body())
File "/usr/local/lib/python3.5/dist-packages/messaging/mms/mms_pdu.py", line 801, in encode_message_body
for char in part.data:
File "/usr/local/lib/python3.5/dist-packages/messaging/mms/message.py", line 552, in data
self._data = f.read()
File "/usr/lib/python3.5/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Do you have any clue ? Installation was made using pip or pip3.

Thank you,

Regards

py3k support is partially broken

The fix for 7bit decoding broke py3k support:

 test_encoding_multipart_7bit (messaging.test.test_encoding.TestEncodingFunctions) ... Traceback (most recent call last):
 File "/home/pablo/devel/git/python-messaging/build/lib.linux-i686-3.1/messaging/gsm0338.py", line 395, in is_valid_gsm_text
      text.encode("gsm0338")
 TypeError: encoder did not return a bytes object (type=str)

Decoding process crashes when PDU length is odd

I have noticed that sometimes my GSM modem send me a PDU which length is odd.

This causes the library to crash, with following message:

File "/usr/lib/python2.6/site-packages/python_messaging-0.3.0-py2.6.egg/messaging/pdu.py", line 169, in decode_pdu
d = StringIO(bytes_to_str(unhexlify(pdu)))
TypeError: Odd-length string

Is it something related to my hardware or is it a bug? Hardware's technical support said PDU length can be odd and actually I can't find out anything on the internet saying that.

How may I resolve?

Solution to problems with Polish characters

Hi,

Your library isn't properly converting Polish characters like ą, ś, ę, ć etc. from UTF-8 to UCS2. The resulting data in the PDU gets malformed and after sending it through a GSM modem, the text becomes just a bunch of random characters.
To fix that, you need to change your pack_8bits_to_ucs2 function in messaging/utils.py. Here's how it should look like in order for it to work properly with Polish chars:

def pack_8bits_to_ucs2(message, udh=None):
    # XXX: This does not control the size respect to UDH
    text = message
    nmesg = ''

    if udh is not None:
        text = udh.encode('utf-8', 'ignore') + text

    for n in unicode(text, "utf-8"):
        nmesg += chr(ord(n) >> 8) + chr(ord(n) & 0xFF)
    mlen = len(text.decode("utf-8")) * 2
    message = chr(mlen) + nmesg
    return encode_str(message)

Issue in timestap

mismatch in decoding pdu sms delivery time
example:
text mode:
at+cmgr=5
+CMGR: "REC READ","+917618799612",,"17/10/05,11:54:04+22"
hg

pdu mode:
at+cmgr=5
+CMGR: 1,,21
0791198954800710040C9119678197692100007101501145402202E833

output:

pdu = "0791198954800710040C9119678197692100007101501145402202E833"
sms = SmsDeliver(pdu)
print sms.date
2017-10-05 06:24:04

Decoding PDU Manually and Sending Empty SMS?

How can I send an empty SMS with python-messaging?

I was trying to use your returned PDU and locate and set the TP-PID octet using this guide on SMS data format, but was not able to parse the output PDU.
SmsSubmit("125", "hello") yields 001100038121F50000FF05E8329BFD06

What are the first 6 octets, 001100 for?
Also, if I ignore those and I am understanding correctly:
03 = length of to address (3 octets)
81 = unknown phone number type
21F5 = 125 phone number
00 = TP-PID??
00 = TP-DCS??
FF 05 E8 32 9B FD 06 = time stamp??

At this point, I think I am doing something wrong. I don't think this is following the same format as that guide.

Any ideas?

MMS text attachment

According to SMIL, src attribute value should contain attachment name not the text itself. Please fix. :)

How get a MMS message?

Hi, the content of the tutorials folder isnt enough to successfully retrieve a mms message from the mmsc, I will glad if you describe how do it.

consider project rename for debian packaging

Hello Pablo,

I am looking at packaging this software for inclusion into debian and ubuntu.

One thing that comes to mind is that "messaging" is a very generic term, and doesn't really help users determine whether they would want this package installed on their systems or not.

Is there any chance you'd consider a different name that gives an indication that this module is to be used for SMS/MMS type things? As an example, here are the names of other python packages that already exist in debian/ubuntu:

http://pastebin.ubuntu.com/628062/

If you want to keep this name, that is fine, and it will not hinder inclusion by debian; but it is something to think about.

Please let me know what you think.

Thanks!
/ac

python-messaging Failed to handle HTTP request

I get this error when I follow the encode and send an MMS. My exact code is below.

PROXY RESPONSE HTTP/1.0 200 OK
content-type: application/vnd.wap.mms-message
content-length: 59
Connection: close
Date: Sat, 05 Jan 2019 16:36:44 GMT
Server: Mavenir Web Application Server

���1234�����,�Failed to handle HTTP request in Mm1Server

Code used to encode and send:

from messaging.mms.message import MMSMessage, MMSMessagePage

mms = MMSMessage()
mms.headers['To'] = '+212XXXXXXX/TYPE=PLMN'
mms.headers['Message-Type'] = 'm-send-req'
mms.headers['Subject'] = 'Test python-messaging.mms'

slide1 = MMSMessagePage()
slide1.add_image('/home/richard/screensaver/TolleConscQte.jpg')
slide1.add_text('This first slide, is a step towards enlightenment.')

slide2 = MMSMessagePage()
slide2.set_duration(4500)
slide2.add_image('/home/richard/screensaver/TollePastALL.jpg', 1500)
slide2.add_text('This second slide is a second step towards enlightenment.', 500, 3500)

mms.add_page(slide1)
mms.add_page(slide2)

payload = mms.encode()

sending the MMS

from cStringIO import StringIO
import socket

gw_host, gw_port = "10.188.239.143", 80 #ting

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((gw_host, gw_port))
s.send("POST %s HTTP/1.0\r\n" % "http://wholesale.mmsmvno.com/mms/wapenc")
s.send("Content-Type: application/vnd.wap.mms-message\r\n")
s.send("Content-Length: %d\r\n\r\n" % len(payload))

s.sendall(payload)

buf = StringIO()

while True:
data = s.recv(4096)
if not data:
break

buf.write(data)

s.close()
data = buf.getvalue()
buf.close()

print "PROXY RESPONSE", data

sms.cnt and sms.seq

Hi,

Giving sms.data i'm taking the results.
same with sms.text and sms.number
But sms.cnt or sms.seq gives error.
How can i put in variables the cnt and seq values?

Thank u!

sms.class = 0 invalid syntax

Hi

I tried the example, but it doesn't work, it says "invalid syntax"
Of course on my pc I used my phone number

from messaging.sms import SmsSubmit

sms = SmsSubmit("+44123231231", "hey how's it going?")
sms.class = 0
pdu = sms.to_pdu()[0]

print pdu.length, pdu.pdu

result:
File "send_sms.py", line 6
sms.class = 0
^
SyntaxError: invalid syntax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.