Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Email
- @@blacklist = Array.new
- @@reg = /\A([-a-z0-9]+[\w\.\-\+]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
- def initialize(mailbox, host)
- @host = host
- @address = "#{mailbox}@#{host}"
- end
- def blacklisted?
- return true if @@blacklist.include? @host
- end
- def host_exists?
- puts "hosting #{@host}"
- if @host
- return true if `host #{@host}`.include? @host
- add_to_blacklist!
- return false
- end
- return false
- end
- def valid?
- puts "is #{@address} valid?"
- return true if @@reg.match @address
- false
- end
- def to_s
- @address
- end
- def add_to_blacklist!
- @@blacklist << @host
- end
- end
- class Message
- require 'net/smtp'
- def initialize(from, subject, body)
- @from = from
- @subject = subject
- @body = body
- end
- def send(to, server)
- begin
- if @from.host_exists? && @from.valid? && !@from.blacklisted?
- Net::SMTP.start(server, 25) do |smtp|
- smtp.send_message msg, @from, to.to_s
- end
- end
- rescue Net::SMTPFatalError
- to.add_to_blacklist!
- rescue Net::SMTPServerBusy
- to.add_to_blacklist!
- end
- end
- def msg
- "Subject:#{@subject}\r\n#{@body.to_s}"
- end
- end
- class IMAP
- require 'net/imap'
- def initialize(login, password)
- @connection = Net::IMAP.new('imap.gmail.com', 993, true)
- @connection.login(login, password)
- end
- def select_folder(folder)
- @connection.select(folder)
- end
- def all_mail
- @connection.uid_search(['ALL'])
- end
- def get_message(id)
- @connection.uid_fetch(id, "(UID RFC822.SIZE ENVELOPE BODY[TEXT])")[0]
- end
- def get_message_in_array(id)
- orig = self.get_message(id)
- return [Email.new( orig.attr["ENVELOPE"].from.first.mailbox ,orig.attr["ENVELOPE"].from.first.host), orig.attr["ENVELOPE"].subject, orig.attr["BODY[TEXT]"] ]
- end
- def logout
- @connection.logout
- end
- end
- if ARGV[0].to_s == '-h'
- puts "spamer.rb username password to server -f folder"
- exit
- end
- username = ARGV.shift
- password = ARGV.shift
- to = ARGV.shift.split("@")
- server = ARGV.shift
- folder = "[Gmail]/Spam"
- while opt = ARGV.shift
- case opt.to_s
- when "-f"
- folder = ARGV.shift
- end
- end
- begin
- im = IMAP.new(username, password)
- im.select_folder(folder)
- to = Email.new(to[0], to[1])
- for id in im.all_mail
- mail = im.get_message_in_array(id)
- msg = Message.new(mail[0], mail[1], mail[2])
- puts "Sending from: #{mail[0]}"
- msg.send(to, server)
- end
- rescue Net::IMAP::ByeResponseError
- retry
- end
Add Comment
Please, Sign In to add comment