Skip to content

Commit

Permalink
#8 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 1, 2018
1 parent cbe511c commit 037940b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
8 changes: 4 additions & 4 deletions bin/rumble
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ begin
'Full SMTP From field, e.g. "John Doe <jd@example.com>"',
required: true
o.string '--host', 'SMTP host name', required: true
o.string '--port', 'SMTP port number', default: 25
o.string '--port', 'SMTP port number (25 by default)', default: 25
o.string '--user', 'SMTP user name', required: true
o.string '--password', 'SMTP password', required: true
o.string '--subject', 'Email subject', required: true
Expand All @@ -64,9 +64,9 @@ begin
o.string '--resume', 'Email address from which we should resume'
o.string '--skip', 'File name with emails that opted-out (black list)'
o.string '--test', 'Email address to use instead of the real user list'
o.string '--col0', 'First name columm', default: 0
o.string '--col1', 'Last name columm', default: 1
o.string '--col2', 'Email columm', default: 2
o.string '--col-first', 'First name columm (0 by default)', default: 0
o.string '--col-last', 'Last name columm (1 by default)', default: 1
o.string '--col-email', 'Email columm (2 by default)', default: 2
end
rescue Slop::Error => ex
raise StandardError, "#{ex.message}, try --help"
Expand Down
20 changes: 13 additions & 7 deletions lib/rumble.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def send
)
skip = @opts[:skip] ? File.readlines(@opts[:skip]).map(&:strip) : []
if @opts[:test]
emails = [['John', 'Doe', @opts[:test]]]
rcpt = []
rcpt[@opts['col-first'].to_i] = 'John'
rcpt[@opts['col-last'].to_i] = 'Doe'
rcpt[@opts['col-email'].to_i] = @opts[:test]
emails = [rcpt]
else
raise '--csv is required' unless @opts[:csv]
emails = CSV.read(@opts[:csv])
Expand All @@ -56,19 +60,21 @@ def send
puts "Sending #{emails.length} email(s) as #{from}"
domain = from.strip.gsub(/^.+@|>$/)
emails.each do |array|
first = (array[@opts[:col0].to_i] || '').strip
last = (array[@opts[:col1].to_i] || '').strip
email = array[@opts[:col2].to_i]
email = array[@opts['col-email'].to_i]
unless email
puts Rainbow('Email is absent').red
puts "Email is #{Rainbow('absent').red} \
at the column ##{@opts['col-email'].to_i}: #{array}"
next
end
email = email.strip.downcase
if sent.include?(email)
puts Rainbow('duplicate').red
puts "#{Rainbow('Duplicate').red} at: #{array}"
next
end
sent.push(email)
first = (array[@opts['col-first'].to_i] || '').strip
last = (array[@opts['col-last'].to_i] || '').strip
first, last = first.split(' ', 2) if last.empty? && first.include?(' ')
name = "#{first.strip} #{last.strip}".strip
address = email
address = "#{name} <#{email}>" unless name.empty?
Expand All @@ -82,7 +88,7 @@ def send
.render(markdown)
if ignore
if @opts[:resume].downcase != email
puts "ignored, waiting for #{@opts[:resume]}"
puts "#{Rainbow('ignored').orange}, waiting for #{@opts[:resume]}"
next
end
ignore = false
Expand Down

0 comments on commit 037940b

Please sign in to comment.