Skip to content

Instantly share code, notes, and snippets.

@evandrojr
Last active August 13, 2018 00:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evandrojr/f3ea0245c9a4c1c88005f3ab17f21e17 to your computer and use it in GitHub Desktop.
Save evandrojr/f3ea0245c9a4c1c88005f3ab17f21e17 to your computer and use it in GitHub Desktop.
Extract all emails from files inside a directory. Writen in Crystal lang
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