Module: SipoMailer

Defined in:
lib/sipo_mailer/utils/testik.rb,
lib/sipo_mailer.rb,
lib/sipo_mailer/email.rb,
lib/sipo_mailer/config.rb,
lib/sipo_mailer/utils/timer.rb,
lib/sipo_mailer/models/types.rb,
lib/sipo_mailer/models/contact.rb,
lib/sipo_mailer/utils/installer.rb,
lib/sipo_mailer/models/attachment.rb,
lib/sipo_mailer/models/address_book.rb

Overview

Description

Defined Under Namespace

Modules: Installer, Models Classes: Config, Mailer, Testik, Timer

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.address_bookObject

Returns the value of attribute address_book.



17
18
19
# File 'lib/sipo_mailer.rb', line 17

def address_book
  @address_book
end

.configObject

Returns the value of attribute config.



17
18
19
# File 'lib/sipo_mailer.rb', line 17

def config
  @config
end

Class Method Details

.performObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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