<commit_before>defmodule Mail.Receive do
  require Logger
  @hashid Hashids.new(salt: Application.get_env(:mailer, :hashid_salt))

  def receive_message(from, to, data) do
    email = data
    |> Mailman.Email.parse!
    |> IO.inspect

    case extract_group_id(to) do
      {:error, _} -> 
      Logger.info("Email: Received email, black hole")
      nil
      {:ok, group_id} when is_integer(group_id) -> try_forward(group_id, email)
    end
  end

  def try_forward(group_id, email) do
    group = Survey.DesignGroup.get(group_id)
    if !group do
      Logger.info("Email: No such design group")
      %Mailman.Email{from: "<EMAIL>", 
        to: email.from, 
        subject: "No such design group", 
        text: "You just sent an email to a design group that does not exist"}
      |> Mail.schedule_send
    else
      user = User.get_by_email(email.from)    
      if !user do
      Logger.info("Email: User not member of design group")
        %Mailman.Email{from: "<EMAIL>", 
          to: email.from, 
          subject: "Not member of design group", 
          text: "No member of this design group has your email. Make sure you use the email that you 
          registered with EdX to respond to messages."}
        |> Mail.schedule_send
      else
        Logger.info("Email: Received valid group mail")
        content = if email.html == "", do: email.text, else: email.html
        Mail.send_group_email(user.design_group_id, user.id, user.nick, email.subject, 
          content, false)
      end
    end
  end

  def extract_group_id(to) do
    if String.contains?(to, <EMAIL>") do
      hash = String.replace(to, <EMAIL>", "")
      Hashids.decode(@hashid, hash)
    else
      {:error, :not_design_group}
    end
  end

  def group_address(id) do
    hash = Hashids.encode(@hashid, id)
  end
end
<commit_msg>Quick fix<commit_after>defmodule Mail.Receive do
  require Logger
  @hashid Hashids.new(salt: Application.get_env(:mailer, :hashid_salt))

  def receive_message(from, to, data) do
    email = data
    |> Mailman.Email.parse!
    |> IO.inspect

    case extract_group_id(to) do
      {:error, _} -> 
      Logger.info("Email: Received email, black hole")
      nil
      {:ok, group_id} when is_integer(group_id) -> try_forward(group_id, email)
    end
  end

  def try_forward(group_id, email) do
    group = Survey.DesignGroup.get(group_id)
    if !group do
      Logger.info("Email: No such design group")
      %Mailman.Email{from: "<EMAIL>", 
        to: email.from, 
        subject: "No such design group", 
        text: "You just sent an email to a design group that does not exist"}
      |> Mail.schedule_send
    else
      user = User.get_by_email(email.from)    
      if !user do
      Logger.info("Email: User not member of design group")
        %Mailman.Email{from: "<EMAIL>", 
          to: email.from, 
          subject: "Not member of design group", 
          text: "No member of this design group has your email. Make sure you use the email that you 
          registered with EdX to respond to messages."}
        |> Mail.schedule_send
      else
        Logger.info("Email: Received valid group mail")
        content = if email.html == "", do: email.text, else: email.html
        Mail.send_group_email(user.design_group_id, user.id, user.nick, email.subject, 
          content, false)
      end
    end
  end

  def extract_group_id([to]) do
    if String.contains?(to, <EMAIL>") do
      hash = String.replace(to, <EMAIL>", "")
      Hashids.decode(@hashid, hash)
    else
      {:error, :not_design_group}
    end
  end

  def group_address(id) do
    hash = Hashids.encode(@hashid, id)
  end
end

{'fraction_non_alphanumeric': 0.10886214442013128, 'fraction_numerical': 0.0, 'mean_word_length': 2.5367504835589942, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1026957', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1141, 'n_words': 341}