Last active
August 13, 2018 00:26
-
-
Save evandrojr/f3ea0245c9a4c1c88005f3ab17f21e17 to your computer and use it in GitHub Desktop.
Extract all emails from files inside a directory. Writen in Crystal lang
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
dir = "msgs/" | |
emails = Set(String).new | |
errors_count = 0 | |
msgs = Dir.entries(dir) | |
msgs.each { |msg| | |
next if msg == "." || msg == ".." | |
begin | |
texto = File.read(dir + msg) | |
matches = texto.scan(/[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,64}/) | |
p matches[0][0] | |
emails.add(matches[0][0]) | |
rescue | |
errors_count = errors_count + 1 | |
end | |
} | |
p emails | |
p "Total de mensagens #{msgs.size - 2}" | |
p "Errors total: #{errors_count}" | |
output = "" | |
emails.each {|email| output=output + email + "\n"} | |
File.write("TODOS_EMAILS.txt",output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment