@classmethod<EOL><INDENT>def from_email_message(cls, message, local_id=None):<DEDENT>
result = cls()<EOL>if local_id is not None:<EOL><INDENT>result.local_id = id<EOL><DEDENT>message_id = message.get('<STR_LIT>')<EOL>if message_id:<EOL><INDENT>result.message_id_supplied = True<EOL>result.message_id = message_id<EOL><DEDENT>result.mime_version = message.get('<STR_LIT>')<EOL>dates = message.get_all('<STR_LIT>', [])<EOL>result.orig_date_list.extend([parse_mail_date(d) for d in dates])<EOL>result.from_list.extend(message.get_all('<STR_LIT>', []))<EOL>result.sender_list.extend(message.get_all('<STR_LIT>', []))<EOL>try:<EOL><INDENT>result.to_list.extend(message.get_all('<STR_LIT>', []))<EOL><DEDENT>except UnicodeError:<EOL><INDENT>print(repr(message['<STR_LIT>']))<EOL>raise<EOL><DEDENT>result.cc_list.extend(message.get_all('<STR_LIT>', []))<EOL>result.bcc_list.extend(message.get_all('<STR_LIT>', []))<EOL>result.in_reply_to_list.extend(message.get_all('<STR_LIT>', []))<EOL>result.references_list.extend(message.get_all('<STR_LIT>', []))<EOL>result.subject_list.extend(message.get_all('<STR_LIT>', []))<EOL>result.comments_list.extend(message.get_all('<STR_LIT>', []))<EOL>result.keywords_list.extend(message.get_all('<STR_LIT>', []))<EOL>headers = [ Header(name=key, value=val) for key, val in message.items() ]<EOL>result.headers.extend(headers)<EOL>if not message.is_multipart():<EOL><INDENT>result.create_single_body()<EOL>if message['<STR_LIT:Content-Type>']:<EOL><INDENT>result.single_body.content_type_list.append(message.get_content_type())<EOL><DEDENT>if message.get_content_charset():<EOL><INDENT>result.single_body.charset_list.append(message.get_content_charset())<EOL><DEDENT>if message.get_filename():<EOL><INDENT>result.single_body.content_name_list.append(message.get_filename())<EOL><DEDENT>result.single_body.create_body_content()<EOL>payload = message.get_payload(decode=False)<EOL>if isinstance(payload, six.binary_type):<EOL><INDENT>charset = message.get_charset()<EOL>if charset is not None:<EOL><INDENT>charset_decoder = codecs.getdecoder(str(charset))<EOL>payload, length = charset_decoder(payload)<EOL><DEDENT>else:<EOL><INDENT>payload = u(payload)<EOL><DEDENT><DEDENT>control_char_map = dict.fromkeys(range(<NUM_LIT:32>))<EOL>for i in [<NUM_LIT:9>, <NUM_LIT:10>, <NUM_LIT>]: <EOL><INDENT>del control_char_map[i]<EOL><DEDENT>payload = u(payload).translate(control_char_map)<EOL>result.single_body.body_content.content = payload<EOL><DEDENT>else:<EOL><INDENT>logger.warn('<STR_LIT>')<EOL><DEDENT>result.eol = EOLMAP[os.linesep]<EOL>return result<EOL>
Convert an :class:`email.message.Message` or compatible message
object into a CERP XML :class:`eulxml.xmlmap.cerp.Message`. If an
id is specified, it will be stored in the Message <LocalId>.

:param message: `email.message.Message` object
:param id: optional message id to be set as `local_id`

:returns: :class:`eulxml.xmlmap.cerp.Message` instance populated
    with message information