Skip to content

Expiry encoder #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions messaging/mms/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self):
'Message-Type': 'm-send-req',
'Transaction-Id': '1234',
'MMS-Version': '1.0',
'Expiry': 3600
'Content-Type': ('application/vnd.wap.multipart.mixed', {}),
}
self.width = 176
Expand Down
34 changes: 34 additions & 0 deletions messaging/mms/mms_pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,3 +994,37 @@ def encode_status_value(status_value):

# Return an unrecognised state if it couldn't be decoded
return [status_values.get(status_value, 'Unrecognised')]

@staticmethod
def encode_expiry_value(expiry_value):
"""
Encodes the expiry value for an MMS message using a relative token
(delta time), not an absolute token (fixed date and time)

encoding: [(total # of octets), (0x81), (# of octets in expiry value), (expiry value)]

Param: expiry_value
Precondition: expiry_value must be an base 10 integer representing the number
of seconds until the MMSC should delete an unaccepted MMS message

Returns: Encoded expiry value
rtype: list of ints
"""
assert type(expiry_value) == int

encoded_expiry_value = []
relativeToken = 129
hexValue = hex(expiry_value)[2:]
length = len(hexValue)

for x in range(length, 0, -2):
if x-2 < 0:
encoded_expiry_value.insert(0, int(hexValue[:x], 16))
else:
encoded_expiry_value.insert(0, int(hexValue[x-2:x], 16))

encoded_expiry_value.insert(0, len(encoded_expiry_value))
encoded_expiry_value.insert(0, relativeToken)
encoded_expiry_value.insert(0, len(encoded_expiry_value))

return encoded_expiry_value