def normalize_mask(mask)
      mask = mask.dup
      mask.gsub!(/\*{2,}/, '*')
      parts = []
      remainder = nil

      if mask !~ /!/ && mask =~ /@/
        remainder = mask
        parts[0] = '*'
      else
        parts[0], remainder = mask.split(/!/, 2)
      end

      if remainder
        remainder.gsub!(/!/, '')
        parts[1..2] = remainder.split(/@/, 2)
      end
      parts[2].gsub!(/@/, '') if parts[2]

      (1..2).each { |i| parts[i] ||= '*' }
      return parts[0] + "!" + parts[1] + "@" + parts[2]
    end
def normalize_mask(mask)
      mask = mask.dup
      mask.gsub!(/\*{2,}/, '*')
      parts = []
      remainder = nil

      if mask !~ /!/ && mask =~ /@/
        remainder = mask
        parts[0] = '*'
      else
        parts[0], remainder = mask.split(/!/, 2)
      end

      if remainder
        remainder.gsub!(/!/, '')
        parts[1..2] = remainder.split(/@/, 2)
      end
      parts[2].gsub!(/@/, '') if parts[2]

      (1..2).each { |i| parts[i] ||= '*' }
      return parts[0] + "!" + parts[1] + "@" + parts[2]
    end
Normalize (expand) an IRC mask.
 @param [String] mask A partial mask (e.g. 'foo*').
 @return [String] A normalized mask (e.g. 'foo*!*@*).