You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: message_id_service.rb
    path of file: ./repos/discourse/lib/email
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Email
  ##
  # Email Message-IDs are used in both our outbound and inbound email
  # flow. For the outbound flow via Email::Sender, we assign a unique
  # Message-ID for any emails sent out from the application.
  # If we are sending an email related to a post, such as through the
  # PostAlerter class, then the Message-ID will contain references to
  # the post ID. The host must also be included on the Message-IDs.
  # The format looks like this:
  #
  # discourse/post/POST_ID@HOST
  #
  # We previously had the following formats, but support for these
  # will be removed in 2023:
  #
  # topic/TOPIC_ID/POST_ID@HOST
  # topic/TOPIC_ID@HOST
  #
  # For the inbound email flow via Email::Receiver, we use Message-IDs
  # to discern which topic and post the inbound email reply should be
  # in response to. In this case, the Message-ID is extracted from the
  # References and/or In-Reply-To headers, and compared with either
  # the IncomingEmail table, the Post table, or the IncomingEmail to
  # determine where to send the reply.
  #
  # See https://datatracker.ietf.org/doc/html/rfc282
    
      def find_post_from_message_ids(message_ids)
        message_ids = message_ids.map { |message_id| message_id_clean(message_id) }

        # TODO (martin) 2023-04-01 We should remove these backwards-compatible
        # formats for the Message-ID and solely use the discourse/post/999@host
        # format.
        topic_ids =
          message_ids
            .map { |message_id| message_id[message_id_topic_id_regexp, 1] }
            .compact
            .map(&:to_i)
        post_ids =
          message_ids
            .map { |message_id| message_id[message_id_post_id_regexp, 1] }
            .compact
            .map(&:to_i)

        post_ids << message_ids
          .map { |message_id| message_id[message_id_discourse_regexp, 1] }
          .compact
          .map(&:to_i)

        post_ids << Post
          .where(outbound_message_id: message_ids)
          .or(Post.where(topic_id: topic_ids, post_number: 1))
          .pluck(:id)
        post_ids << EmailLog.where(message_id: message_ids).pluck(:post_id)
        post_ids << IncomingEmail.where(message_id: message_ids).pluck(:post_id)

        post_ids.flatten!
        post_ids.compact!
        post_ids.uniq!

        return if post_ids.empty?

        Post.where(id: post_ids).order(:created_at).last
      end