diff --git a/messaging/mms/message.py b/messaging/mms/message.py index 6cff8a0..651479a 100644 --- a/messaging/mms/message.py +++ b/messaging/mms/message.py @@ -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 diff --git a/messaging/mms/mms_pdu.py b/messaging/mms/mms_pdu.py index ed44c46..76b5cf8 100644 --- a/messaging/mms/mms_pdu.py +++ b/messaging/mms/mms_pdu.py @@ -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