module SipoMailer
Description
Test
Attributes
address_book[RW]
config[RW]
Public Class Methods
perform()
click to toggle source
# File lib/sipo_mailer.rb, line 23 def self.perform files = Dir[Dir.pwd + '/*.*'] files = files.map { |path| Models::Attachment.new(path) }.select(&:valid?) files = files.reject { |file| file.processed? } if files.none? printf "Žádné soubory ke zpracování\n" exit end printf "Našel jsem %d souborů ke zpracování.\n\n", files.count files = files.reject do |file| if SipoMailer.address_book.find(file.id).nil? printf "Vyřazuji soubor #{file.filename}, číslo #{file.id} nenalezeno v adresáři.\n\n" true else false end end response = nil until %w(a n).include?(response) printf "Poslat %s soubor/ů?\n", files.count print "(a) ano\n" print "(n) ne\n" response = STDIN.gets.strip exit if response == 'n' system('clear') end files.each do |file| to = SipoMailer.address_book.find(file.id).email printf 'Posílám soubor %s na %s', file.filename, to email = Mailer.send(to: to, attachment: file) printf " ok\n\n" if email.sent? end end