Given an email.message.Message, return a set with all email parts to get

    Args:
        message (email.message.Message): email message object
        complete (bool): if True returns all email headers

    Returns:
        set with all email parts
553399
def get_mail_keys(message, complete=True):
    

    if complete:
        log.debug("Get all headers")
        all_headers_keys = {i.lower() for i in message.keys()}
        all_parts = ADDRESSES_HEADERS | OTHERS_PARTS | all_headers_keys
    else:
        log.debug("Get only mains headers")
        all_parts = ADDRESSES_HEADERS | OTHERS_PARTS

    log.debug("All parts to get: {}".format(", ".join(all_parts)))
    return all_parts
619270
def from_mime(cls, message, manager):
        
        text, html, attachments = deconstruct_multipart(message)
        subject = prepare_header(message["Subject"])
        sender = prepare_header(message["From"])
        to = prepare_header(message["To"])
        cc = prepare_header(message["Cc"])
        bcc = prepare_header(message["Bcc"])
        reply_to = prepare_header(message["Reply-To"])
        tag = getattr(message, "tag", None)
        return cls(
            manager=manager,
            From=sender,
            To=to,
            TextBody=text,
            HtmlBody=html,
            Subject=subject,
            Cc=cc,
            Bcc=bcc,
            ReplyTo=reply_to,
            Attachments=attachments,
            Tag=tag,
        )
1091718
def clean_message(message: Message, topmost: bool = False) -> Message:
    
    if message.is_multipart():
        # Don't recurse in already-deleted attachments
        if message.get_content_type() != 'message/external-body':
            parts = message.get_payload()
            parts[:] = map(clean_message, parts)
    elif message_is_binary(message):
        # Don't gut if this is the topmost message
        if not topmost:
            message = gut_message(message)

    return message
1248749
def get_replies_to(self, msg):
        
        mid = msg.get_message_id()
        msg_hash = self.get_messages()
        for m in msg_hash.keys():
            if m.get_message_id() == mid:
                return msg_hash[m]
        return None
1186946
def put(self, message):
        """"""

        # First assemble the complete message string by prefixing the header.
        header = self.HEADER_FORMAT.format(len(message))
        full_message = header + message

        # Then send all bytes of the message.
        sent_count = 0
        while sent_count < len(full_message):
            try:
                msg = full_message[sent_count:]
                msg = msg.encode() if self._encode else msg
                count = self._sock.send(msg)
            except socket.error as err:
                print('error')
                return False
            if count == 0:
                return False
            sent_count += count
        return True
870743
def iscomplete(rawmessage):
    """"""
    if len(rawmessage) < 2:
        return False

    if rawmessage[0] != 0x02:
        raise ValueError('message does not start with 0x02')

    messageBuffer = bytearray()
    filler = bytearray(30)
    messageBuffer.extend(rawmessage)
    messageBuffer.extend(filler)

    msg = _get_msg_class(rawmessage[1])

    if hasattr(msg, 'receivedSize') and msg.receivedSize:
        expectedSize = msg.receivedSize
    else:
        _LOGGER.error('Unable to find a receivedSize for code 0x%x',
                      rawmessage[1])
        return ValueError

    is_expected_size = False
    if len(rawmessage) >= expectedSize:
        is_expected_size = True

    return is_expected_size
402894
def parse_headers(cls, msg):
        
        return list(email.parser.Parser().parsestr(msg).items())
1107982
def parse_message(contact)
      header = contact[0]
      body = contact[1,contact.count]
      items = process_item_body(body)
      combine_header_with_transmission(items, header)
    end
652257
def full_message(attribute, message)
      return message if attribute == :base
      attribute = attribute.to_s

      if self.class.i18n_customize_full_message && @base.class.respond_to?(:i18n_scope)
        attribute = attribute.remove(/\[\d\]/)
        parts = attribute.split(".")
        attribute_name = parts.pop
        namespace = parts.join("/") unless parts.empty?
        attributes_scope = "#{@base.class.i18n_scope}.errors.models"

        if namespace
          defaults = @base.class.lookup_ancestors.map do |klass|
            [
              :"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.attributes.#{attribute_name}.format",
              :"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.format",
            ]
          end
        else
          defaults = @base.class.lookup_ancestors.map do |klass|
            [
              :"#{attributes_scope}.#{klass.model_name.i18n_key}.attributes.#{attribute_name}.format",
              :"#{attributes_scope}.#{klass.model_name.i18n_key}.format",
            ]
          end
        end

        defaults.flatten!
      else
        defaults = []
      end

      defaults << :"errors.format"
      defaults << "%{attribute} %{message}"

      attr_name = attribute.tr(".", "_").humanize
      attr_name = @base.class.human_attribute_name(attribute, default: attr_name)

      I18n.t(defaults.shift,
        default:  defaults,
        attribute: attr_name,
        message:   message)
    end
674763
protected function get_email_from_header($message, $header)
    {
        $value = $message->headers->get($header, false);

        if (strtolower($header) == 'received') {
            // find first email address in all Received headers
            $email = null;
            foreach ((array) $value as $entry) {
                if (preg_match('/[\s\t]+for[\s\t]+<([^>]+)>/', $entry, $matches)) {
                    $email = $matches[1];
                    break;
                }
            }

            $value = $email;
        }

        return (array) $value;
    }
732354
def send_messages(self, messages):
        """"""
        msg_count = 0
        for message in messages:  # .message() triggers header validation
            message.message()
            email.outbox.append(message)
            msg_count += 1

        return msg_count
124053
def from_raw_message(cls, rawmessage):
        """"""
        return AllLinkComplete(rawmessage[2],
                               rawmessage[3],
                               rawmessage[4:7],
                               rawmessage[7],
                               rawmessage[8],
                               rawmessage[9])
1268268
def make_data(self, message):

        

        if not isinstance(message, Message):
            return message
        return message.export(self.transport_content_type)
1299788
def get_addresses(message: list) -> list:
    
    # Need the address so that we know who to send the message back to
    addresses = []
    for address in message:
        # if we hit a blank string, then we've got all the addresses
        if address == b'':
            break
        addresses.append(address)

    return addresses
374011
def prepare_message(user, useralias, addresses, subject, contents, attachments, headers, encoding, newline_to_break=True):
    # check if closed!!!!!! XXX
    
    if isinstance(contents, text_type):
        contents = [contents]
    if isinstance(attachments, text_type):
        attachments = [attachments]

    # merge contents and attachments for now.
    if attachments is not None:
        for a in attachments:
            if not os.path.isfile(a):
                raise TypeError("'{0}' is not a valid filepath".format(a))
        contents = attachments if contents is None else contents + attachments

    has_included_images, content_objects = prepare_contents(contents, encoding)
    msg = MIMEMultipart()
    if headers is not None:
        # Strangely, msg does not have an update method, so then manually.
        for k, v in headers.items():
            msg[k] = v
    if headers is None or "Date" not in headers:
        msg["Date"] = formatdate()

    msg_alternative = MIMEMultipart("alternative")
    msg_related = MIMEMultipart("related")
    msg_related.attach("-- HTML goes here --")
    msg.attach(msg_alternative)
    add_subject(msg, subject)
    add_recipients_headers(user, useralias, msg, addresses)
    htmlstr = ""
    altstr = []
    if has_included_images:
        msg.preamble = "This message is best displayed using a MIME capable email reader."

    if contents is not None:
        for content_object, content_string in zip(content_objects, contents):
            if content_object["main_type"] == "image":
                # all image objects need base64 encoding, so do it now
                email.encoders.encode_base64(content_object["mime_object"])
                # aliased image {'path' : 'alias'}
                if isinstance(content_string, dict) and len(content_string) == 1:
                    for key in content_string:
                        hashed_ref = str(abs(hash(key)))
                        alias = content_string[key]
                    # pylint: disable=undefined-loop-variable
                    content_string = key
                else:
                    alias = os.path.basename(str(content_string))
                    hashed_ref = str(abs(hash(alias)))

                # TODO: I should probably remove inline now that there is "attachments"
                # if string is `inline`, inline, else, attach
                # pylint: disable=unidiomatic-typecheck
                if type(content_string) == inline:
                    htmlstr += '<img src="cid:{0}" title="{1}"/>'.format(hashed_ref, alias)
                    content_object["mime_object"].add_header(
                        "Content-ID", "<{0}>".format(hashed_ref)
                    )
                    altstr.append("-- img {0} should be here -- ".format(alias))
                    # inline images should be in related MIME block
                    msg_related.attach(content_object["mime_object"])
                else:
                    # non-inline images get attached like any other attachment
                    msg.attach(content_object["mime_object"])

            else:
                if content_object["encoding"] == "base64":
                    email.encoders.encode_base64(content_object["mime_object"])
                    msg.attach(content_object["mime_object"])
                elif content_object["sub_type"] not in ["html", "plain"]:
                    msg.attach(content_object["mime_object"])
                else:
                    if newline_to_break:
                        content_string = content_string.replace("\n", "<br>")
                    try:
                        htmlstr += "<div>{0}</div>".format(content_string)
                    except UnicodeEncodeError:
                        htmlstr += u"<div>{0}</div>".format(content_string)
                    altstr.append(content_string)

    msg_related.get_payload()[0] = MIMEText(htmlstr, "html", _charset=encoding)
    msg_alternative.attach(MIMEText("\n".join(altstr), _charset=encoding))
    msg_alternative.attach(msg_related)
    return msg
342893
def get_messages(self, page=0):
        
        endpoint = 'https://outlook.office.com/api/v2.0/me/messages'
        if page > 0:
            endpoint = endpoint + '/?%24skip=' + str(page) + '0'

        log.debug('Getting messages from endpoint: {} with Headers: {}'.format(endpoint, self._headers))

        r = requests.get(endpoint, headers=self._headers)

        check_response(r)

        return Message._json_to_messages(self, r.json())
1374365
def complete_set(self, cmd_param_text, full_cmd, *rest):
        
        complete_value = partial(complete_values, ["updated-value"])
        complete_version = partial(complete_values, [str(i) for i in range(1, 11)])
        completers = [self._complete_path, complete_value, complete_version]
        return complete(completers, cmd_param_text, full_cmd, *rest)