Method: F2IConfig#initialize

Defined in:
lib/feed2imap/config.rb

#initialize(io) ⇒ F2IConfig

Load the configuration from the IO stream TODO should do some sanity check on the data read.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/feed2imap/config.rb', line 42

def initialize(io)
  @conf = YAML::safe_load(io, aliases: true)
  @cache = @conf['cache'] || DEFCACHE
  @dumpdir = @conf['dumpdir'] || nil
  @conf['feeds'] ||= []
  @feeds = []
  @max_failures = (@conf['max-failures'] || 10).to_i

  @updateddebug = false
  @updateddebug = @conf['debug-updated'] if @conf.has_key?('debug-updated')

  @parts = %w(text html)
  @parts = Array(@conf['parts']) if @conf.has_key?('parts') && !@conf['parts'].empty?
  @parts = Set.new(@parts)

  @include_images = true
  @include_images = @conf['include-images'] if @conf.has_key?('include-images')
  @parts << 'html' if @include_images && ! @parts.include?('html')

  @reupload_if_updated = true
  @reupload_if_updated = @conf['reupload-if-updated'] if @conf.has_key?('reupload-if-updated')

  @timeout = if @conf['timeout'] == nil then 30 else @conf['timeout'].to_i end

  @default_email = (@conf['default-email'] || "#{LOGNAME}@#{HOSTNAME}")
  ImapAccount.no_ssl_verify = (@conf.has_key?('disable-ssl-verification') and @conf['disable-ssl-verification'] == true)
  @hostname = HOSTNAME # FIXME: should this be configurable as well?
  @imap_accounts = ImapAccounts::new
   = MaildirAccount::new
  @conf['feeds'].each do |f|
    f['name'] = f['name'].to_s
    if f['disable'].nil?
      uri = URI::parse(Array(f['target']).join(''))
      path = CGI::unescape(uri.path)
      if uri.scheme == 'maildir'
        @feeds.push(ConfigFeed::new(f, , path, self))
      else
        # remove leading slash from IMAP mailbox names
        path = path[1..-1] if path[0,1] == '/'
        @feeds.push(ConfigFeed::new(f, @imap_accounts.(uri), path, self))
      end
    end
  end
end