Reference client for Bitmessage: a P2P encrypted decentralised communication protocol:
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

import logging
from messagetypes import MsgBase
logger = logging.getLogger('default')
class Message(MsgBase):
"""Encapsulate a message"""
# pylint: disable=attribute-defined-outside-init
def decode(self, data):
"""Decode a message"""
# UTF-8 and variable type validator
if isinstance(data["subject"], str):
self.subject = unicode(data["subject"], 'utf-8', 'replace')
self.subject = unicode(str(data["subject"]), 'utf-8', 'replace')
if isinstance(data["body"], str):
self.body = unicode(data["body"], 'utf-8', 'replace')
self.body = unicode(str(data["body"]), 'utf-8', 'replace')
def encode(self, data):
"""Encode a message"""
super(Message, self).__init__()
try:["subject"] = data["subject"]["body"] = data["body"]
except KeyError as e:
logger.error("Missing key %s", e)
def process(self):
"""Process a message"""
logger.debug("Subject: %i bytes", len(self.subject))
logger.debug("Body: %i bytes", len(self.body))