@Override
	protected void read(InputBuffer b) throws IOException, ParsingException {
		VariableLengthIntegerMessage i = getMessageFactory().parseVariableLengthIntegerMessage(b);
		b = b.getSubBuffer(i.length());
		encoding = MessageEncoding.getEncoding(i.getLong());

		i = getMessageFactory().parseVariableLengthIntegerMessage(b);
		b = b.getSubBuffer(i.length());
		long length = i.getLong();

		if (length > b.length() || length < 0) {
			throw new ParsingException("Message too long: " + length);
		}

		data = b.get(0, (int) length);

		switch (encoding) {
		case IGNORE:
			break;

		case TRIVIAL:
			content = new String(data, "UTF-8");
			break;

		case SIMPLE:
			String s = new String(data, "UTF-8").substring(8);
			int index = s.indexOf("\nBody:");

			subject = s.substring(0, index);
			content = s.substring(index + 6);
			break;

		default:
			throw new ParsingException("Unknown encoding: " + encoding);
		}
	}