Created
November 19, 2011 06:50
-
-
Save dantman/1378568 to your computer and use it in GitHub Desktop.
Script to deobfuscate MediaWiki svn USERINFO emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Checkout the svn USERINFO folder into a directory. | |
- Setup this script right next to it and cd to that directory. | |
((ie: You should have ./USERINFO and ./useremails.rb sitting in front of you)) | |
((Note: Users who don't have an e-mail set are omitted from outputs)) | |
- `ruby useremails.rb` will give you a list of svn users, their name, and e-mail | |
- `ruby useremails.rb list` will give you that same list but in a comma separated "Name <email>" format | |
- `ruby useremails.rb obfuscated` will filter the list to only users who have obfuscated their e-mail | |
- `ruby useremails.rb obfuscated list` will take that filtered list and put it in the "Name <email>" format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$obfuscated_only = ARGV.include? 'obfuscated' | |
$list_format = ARGV.include? 'list' | |
def parsefile(file) | |
contents = File.open(file, 'r') { |f| f.read } | |
data = {} | |
contents.split("\n").each { |line| | |
m = /^([\w\s]+):\s*(.*)$/.match(line) | |
next if m.nil? | |
data[m[1].to_sym] = m[2] | |
} | |
data[:user] = File.basename file | |
data | |
end | |
def deobfuscate_email(data) | |
return if data[:email].nil? | |
email = data[:email] # @note Not coppied, this is the same string and it gets modified | |
original_email = email.dup # duplicate so it is not modified | |
name = data[:name].split /\s+/ unless data[:name].nil? | |
email.gsub! /\s+(Who Is A User At The Host Called|at the email provider|<at>|-AT-|\(at?\)|at|#)\s+/, '@' | |
email.gsub! /\s+(<dot>|\(dot\)|d0t|dot)\s+/, '.' | |
email.gsub! "first name + last name (all as one word)", "<Firstname><Lastname>" | |
email.gsub! /<Firstname>/, name.first unless name.nil? | |
email.gsub! /<Lastname>/, name.last unless name.nil? | |
email.sub! /\.haveyouconsiderednotincludingthisphrase/, '' | |
email.sub! /^([-_.\w]+) ([-_.\w]+)$/, '\1@\2' | |
data[:email_obfuscated] = original_email != email | |
end | |
def handleuser(data) | |
deobfuscate_email(data) | |
unless data[:email].nil? or ($obfuscated_only and !data[:email_obfuscated]) | |
if $list_format | |
print "#{data[:name]||data[:user]} <#{data[:email]}>, " | |
else | |
puts "#{data[:user]}: #{data[:name]} <#{data[:email]}>" unless data[:name].nil? | |
puts "#{data[:user]}: #{data[:email]}" if data[:name].nil? | |
end | |
end | |
end | |
Dir.new('USERINFO').each do |file| | |
next if /^\./ =~ file | |
data = parsefile(File.join('USERINFO', file)) | |
handleuser(data) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment