2019-08-09 06:36:59 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from future import standard_library
|
|
|
|
standard_library.install_aliases()
|
|
|
|
from builtins import str
|
|
|
|
from builtins import *
|
2016-11-12 16:20:45 +00:00
|
|
|
from debug import logger
|
|
|
|
from messagetypes import MsgBase
|
|
|
|
|
2016-11-15 16:10:33 +00:00
|
|
|
|
2016-11-12 16:20:45 +00:00
|
|
|
class Message(MsgBase):
|
|
|
|
def __init__(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
def decode(self, data):
|
2016-11-15 16:10:33 +00:00
|
|
|
# UTF-8 and variable type validator
|
|
|
|
if type(data["subject"]) is str:
|
2019-08-09 06:36:59 +00:00
|
|
|
self.subject = str(data["subject"], 'utf-8', 'replace')
|
2016-11-15 16:10:33 +00:00
|
|
|
else:
|
2019-08-09 06:36:59 +00:00
|
|
|
self.subject = str(str(data["subject"]), 'utf-8', 'replace')
|
2016-11-15 16:10:33 +00:00
|
|
|
if type(data["body"]) is str:
|
2019-08-09 06:36:59 +00:00
|
|
|
self.body = str(data["body"], 'utf-8', 'replace')
|
2016-11-15 16:10:33 +00:00
|
|
|
else:
|
2019-08-09 06:36:59 +00:00
|
|
|
self.body = str(str(data["body"]), 'utf-8', 'replace')
|
2016-11-03 21:41:36 +00:00
|
|
|
|
2016-11-12 16:20:45 +00:00
|
|
|
def encode(self, data):
|
|
|
|
super(Message, self).encode()
|
|
|
|
try:
|
|
|
|
self.data["subject"] = data["subject"]
|
|
|
|
self.data["body"] = data["body"]
|
|
|
|
except KeyError as e:
|
2019-07-05 08:45:12 +00:00
|
|
|
logger.error("Missing key %s", e)
|
2016-11-12 16:20:45 +00:00
|
|
|
return self.data
|
|
|
|
|
2016-11-03 21:41:36 +00:00
|
|
|
def process(self):
|
2016-11-12 16:20:45 +00:00
|
|
|
logger.debug("Subject: %i bytes", len(self.subject))
|
|
|
|
logger.debug("Body: %i bytes", len(self.body))
|