<commit_before>class UploadMailbox < ActiveRecord::Base
  
  EMAIL_DOMAIN = "upload.documentcloud.org"
  
  belongs_to :membership

  before_validation :ensure_recipient

  # TODO: Add email format validation here
  validates :sender, :recipient, presence: true
  
  def self.lookup(sender, key)
    (self.where(sender:sender, recipient: key) || []).first
  end
  
  def recipient_address
    "#{self.recipient}@#{EMAIL_DOMAIN}"
  end
  
  def ensure_recipient
    self.recipient ||= "#{membership.organization.slug}-#{SecureRandom.hex(4)}"
  end
end<commit_msg>Validate format of mailbox sender email<commit_after>class UploadMailbox < ActiveRecord::Base
  
  EMAIL_DOMAIN = "upload.documentcloud.org"
  
  belongs_to :membership

  before_validation :ensure_recipient
  validates :recipient, presence: true
  validates :sender, {
    presence: true, format: {with: DC::Validators::EMAIL}
  }

  def self.lookup(sender, key)
    (self.where(sender:sender, recipient: key) || []).first
  end
  
  def recipient_address
    "#{self.recipient}@#{EMAIL_DOMAIN}"
  end
  
  def ensure_recipient
    self.recipient ||= "#{membership.organization.slug}-#{SecureRandom.hex(4)}"
  end
end
{'fraction_non_alphanumeric': 0.11864406779661017, 'fraction_numerical': 0.001694915254237288, 'mean_word_length': 4.41743119266055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '332320', 'n_tokens_mistral': 406, 'n_tokens_neox': 401, 'n_words': 80}