Extracts email message information if it uses the new Mailman format
        Args:
            content: BeautifulSoup

        Returns: List[str]
484062
def new_format(self, navbar: BeautifulSoup, content: BeautifulSoup) -> List[str]:

        
        
        sender = content.find(id='from').text.split('via')[0][6:].strip()
        date_str = content.find(id='date').text.split(': ')[1].strip()
        date = parsedate_to_datetime(date_str).isoformat()[:19]
        body = content.find(id='body').text.strip()
        nxt, rep_to = None, None
        
        links = navbar.findAll('a')
        for l in links:
            if 'Next in thread' in str(l):
                nxt = '/'.join(self.email_url.split('/')[:-1]) + '/' + l['href']
                nxt = nxt[1:] if nxt[0] == '/' else nxt
            elif 'reply to' in str(l):
                rep_to = '/'.join(self.email_url.split('/')[:-1]) + '/' + l['href']
                rep_to = rep_to[1:] if rep_to[0] == '/' else rep_to
        return [str(i) for i in [sender, date, body, nxt, rep_to]]
788322
def get_message_plain_text(msg: Message):
    
    if msg.body:
        return msg.body

    if BeautifulSoup is None or not msg.html:
        return msg.html

    plain_text = '\n'.join(line.strip() for line in
                           BeautifulSoup(msg.html, 'lxml').text.splitlines())
    return re.sub(r'\n\n+', '\n\n', plain_text).strip()
35098
def info(self):
        '''
        '''
        if sys.version_info[0] == 2:
            return mimetools.Message(io.StringIO(str(self._response.fields)))
        else:
            return email.message_from_string(str(self._response.fields))
137158
def _parse_content_type(content_type: Optional[str]) -> Tuple[Optional[str], str]:
    
    if not content_type:
        return None, "utf-8"
    else:
        type_, parameters = cgi.parse_header(content_type)
        encoding = parameters.get("charset", "utf-8")
        return type_, encoding
805512
def serialize_email_messages(messages: List[EmailMessage]):
    
    return [
        base64.b64encode(zlib.compress(pickle.dumps(m, protocol=4))).decode()
        for m in messages
    ]
382197
def get_raw_email(self):
        
        if 'email' in self.payload:
            raw_email = email.message_from_string(self.payload['email'])
            return raw_email
        else:
            return None
957442
def content(self):  # type: () -> object
        
        as_text = self.content_type in _content_types.UTF8_TYPES

        return self.get_data(as_text=as_text)
1209804
def print_msg(contentlist):
        # type: (Union[AnyStr, List[AnyStr], Tuple[AnyStr]]) -> AnyStr
        """"""
        if isinstance(contentlist, list) or isinstance(contentlist, tuple):
            return '\n'.join(contentlist)
        else:  # strings
            if len(contentlist) > 1 and contentlist[-1] != '\n':
                contentlist += '\n'
            return contentlist
134371
def _get_request_content(self, message=None):
        '''
        '''
        message = self._cast_message(message=message)
        return message.json()
224335
def parse_content_type(content_type):
    
    if '; charset=' in content_type:
        return tuple(content_type.split('; charset='))
    else:
        if 'text' in content_type:
            encoding = 'ISO-8859-1'
        else:
            try:
                format = formats.find_by_content_type(content_type)
            except formats.UnknownFormat:
                encoding = 'ISO-8859-1'
            else:
                encoding = format.default_encoding or 'ISO-8859-1'

        return (content_type, encoding)
1228523
def to_message(self):
        

        self.validate()
        
        bodies = [(self.body, 'text/plain'), (self.html, 'text/html')]

        for idx, (val, content_type) in enumerate(bodies):
            if val is None:
                bodies[idx] = None
            elif isinstance(val, Attachment):
                bodies[idx] = val.to_mailbase(content_type)
            else:
                # presumed to be a textual val
                attachment = Attachment(
                    data=val,
                    content_type=content_type,
                    transfer_encoding='quoted-printable',
                    disposition='inline'
                    )
                bodies[idx] = attachment.to_mailbase(content_type)

        body, html = bodies

        base = MailBase([
            ('To', ', '.join(self.recipients)),
            ('From', self.sender),
            ('Subject', self.subject),
            ])

        # base represents the outermost mime part; it will be one of the
        # following types:
        #
        # - a multipart/mixed type if there are attachments.  this
        #   part will contain a single multipart/alternative type if there
        #   is both an html part and a plaintext part (the alternative part
        #   will contain both the text and html), it will contain
        #   a single text/plain part if there is only a plaintext part,
        #   or it will contain a single text/html part if there is only
        #   an html part.  it will also contain N parts representing
        #   each attachment as children of the base mixed type.
        #
        # - a multipart/alternative type if there are no attachments but
        #   both an html part and a plaintext part.  it will contain
        #   a single text/plain part if there is only a plaintext part,
        #   or it will contain a single text/html part if there is only
        #   an html part.
        #
        # - a text/plain type if there is only a plaintext part
        #
        # - a text/html type if there is only an html part

        if self.cc:
            base['Cc'] = ', '.join(self.cc)
            
        if self.extra_headers:
            base.update(dict(self.extra_headers))

        if self.attachments:
            base.set_content_type('multipart/mixed')
            altpart = MailBase()
            base.attach_part(altpart)
        else:
            altpart = base
            
        if body and html:
            altpart.set_content_type('multipart/alternative')
            altpart.set_body(None)
            # Per RFC2046, HTML part comes last in multipart/alternative
            altpart.attach_part(body)
            altpart.attach_part(html)
        elif body is not None:
            altpart.merge_part(body)
        elif html is not None:
            altpart.merge_part(html)

        for attachment in self.attachments:
            attachment_mailbase = attachment.to_mailbase()
            base.attach_part(attachment_mailbase)

        return to_message(base)
180872
def decode_message_headers(msg_headers):
    '''
    
    '''

    headers_to_decode = ['from', 'reply-to', 'subject', 'to']

    for item in headers_to_decode:
        return_list = []
        try:
            # decode the header
            decoded_header = pyzmail_decode_mail_header(msg_headers[item][0])
            # add the header to a list as we want to return a list
            return_list.append(decoded_header)
            # replace the item in the dict with a decoded version
            msg_headers[item] = return_list

        except KeyError:
            pass

    return msg_headers
537623
def message_to_objects(
        message: Dict, sender: str, sender_key_fetcher: Callable[[str], str] = None, user: UserType = None,
) -> List:
    
    # We only really expect one element here for ActivityPub.
    return element_to_objects(message)
1282110
def get_matching(content, match):
    
    if match != "":
        lines = [line for line in content.split("\n") if match in line]
        content = "\n".join(lines)
    return content
639000
def contents(self):
        
        if not hasattr(self, "_content"):
            self._content = self.get_content()
        return self._content
488290
def message(self):
        
        return '\n'.join(
            [self.from_email, str(self.to), self.subject, self.body])
1357407
def _process_attachments(self, email):
        
        for a in email.attachments:
            if isinstance(a, MIMEBase):
                if not a.is_multipart():
                    obj = {
                        'filename': a.get_filename(),
                        'content_type': a.get_content_type(),
                    }
                    if a.get('content-transfer-encoding') == 'base64':
                        obj['content'] = a.get_payload()
                        obj['encoded'] = True
                    else:
                        obj['content'] = a.get_payload(decode=True)
                    yield obj
            else:
                yield {
                    'filename': a[0],
                    'content_type': a[2],
                    'content': a[1],
                }