<commit_before>class Mailman < ActionMailer::Base

  # Method for processing incoming messages
  # pre: email (as passed from ActionMailer receieve) 
  def receive(email)
    # TODO: clean up with regexp and logic 

    s_pre, s_domain = email.to.first.split(/\@/)
    s_list, s_topic = s_pre.split(/\+/)

    # Don't storm
    if(s_list == "mailer" || s_list == "noreply")
      exit
    end

    # Make sure the list exists
    unless(List.exists?(:short_name => s_list))
      Mailman.deliver_no_such_list(email)
      exit
    end

    list = List.find_by_short_name(s_list)

    # Add virtual fields for other functions to use
    #email.list = list


    # Make sure they are in the list (allowed to post)
    unless(list.subscribers.exists?(:email => email.from))
      Mailman.deliver_cannot_post(list, email)
      exit
    end

    # Check if this is a response to an existing topic or a new message
    if(s_pre =~ /\+/) then
      unless(Topic.exists?(:key => s_topic)) then
        Mailman.deliver_no_such_topic(list, email)
      end

      topic = Topic.find_by_key(s_topic)

      # Strip out the subject crap
      # Can't use gsub! because subject isn't actually a string unless coerced
      email.subject = email.subject.gsub(/\[#{list.short_name}\]/, "")

    else
      topic = list.topics.create(
        :name => email.subject
        )

      topic.key = sprintf("%08d", topic.id)
      topic.save
    end<commit_msg>Fixed redundant RE: in subject<commit_after>class Mailman < ActionMailer::Base

  # Method for processing incoming messages
  # pre: email (as passed from ActionMailer receieve) 
  def receive(email)
    # TODO: clean up with regexp and logic 

    s_pre, s_domain = email.to.first.split(/\@/)
    s_list, s_topic = s_pre.split(/\+/)

    # Don't storm
    if(s_list == "mailer" || s_list == "noreply")
      exit
    end

    # Make sure the list exists
    unless(List.exists?(:short_name => s_list))
      Mailman.deliver_no_such_list(email)
      exit
    end

    list = List.find_by_short_name(s_list)

    # Add virtual fields for other functions to use
    #email.list = list


    # Make sure they are in the list (allowed to post)
    unless(list.subscribers.exists?(:email => email.from))
      Mailman.deliver_cannot_post(list, email)
      exit
    end

    # Check if this is a response to an existing topic or a new message
    if(s_pre =~ /\+/) then
      unless(Topic.exists?(:key => s_topic)) then
        Mailman.deliver_no_such_topic(list, email)
      end

      topic = Topic.find_by_key(s_topic)

      # Strip out the subject crap
      # Can't use gsub! because subject isn't actually a string unless coerced
      email.subject = email.subject.gsub(/\[#{list.short_name}\]/, "")
      # Clean out RE and FW's
      email.subject = email.subject.gsub(/([rR][eE]:\ *){2,}/, "RE: ")

    else
      topic = list.topics.create(
        :name => email.subject
        )

      topic.key = sprintf("%08d", topic.id)
      topic.save
    end
{'fraction_non_alphanumeric': 0.11359093937375084, 'fraction_numerical': 0.0016655562958027982, 'mean_word_length': 2.5964071856287427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '5279624', 'n_tokens_mistral': 1010, 'n_tokens_neox': 962, 'n_words': 268}