Class: F2IConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/feed2imap/config.rb

Overview

Feed2imap configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#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

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def cache
  @cache
end

#default_emailObject (readonly)

Returns the value of attribute default_email.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def default_email
  @default_email
end

#dumpdirObject (readonly)

Returns the value of attribute dumpdir.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def dumpdir
  @dumpdir
end

#feedsObject (readonly)

Returns the value of attribute feeds.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def feeds
  @feeds
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def hostname
  @hostname
end

#imap_accountsObject (readonly)

Returns the value of attribute imap_accounts.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def imap_accounts
  @imap_accounts
end

#include_imagesObject (readonly)

Returns the value of attribute include_images.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def include_images
  @include_images
end

#max_failuresObject (readonly)

Returns the value of attribute max_failures.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def max_failures
  @max_failures
end

#partsObject (readonly)

Returns the value of attribute parts.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def parts
  @parts
end

#reupload_if_updatedObject (readonly)

Returns the value of attribute reupload_if_updated.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def reupload_if_updated
  @reupload_if_updated
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def timeout
  @timeout
end

#updateddebugObject (readonly)

Returns the value of attribute updateddebug.



38
39
40
# File 'lib/feed2imap/config.rb', line 38

def updateddebug
  @updateddebug
end

Instance Method Details

#to_sObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/feed2imap/config.rb', line 87

def to_s
  s =  "Your Feed2Imap config :\n"
  s += "=======================\n"
  s += "Cache file: #{@cache}\n\n"
  s += "Imap accounts I'll have to connect to :\n"
  s += "---------------------------------------\n"
  @imap_accounts.each_value { |i| s += i.to_s + "\n" }
  s += "\nFeeds :\n"
  s +=   "-------\n"
  i = 1
  @feeds.each do |f|
    s += "#{i}. #{f.name}\n"
    s += "    URL: #{f.url}\n"
    s += "    IMAP Account: #{f.imapaccount}\n"
    s += "    Folder: #{f.folder}\n"

    if not f.wrapto
      s += "    Not wrapped.\n"
    end

    s += "\n"
    i += 1
  end
  s
end