summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Nussbaum <lucas@lucas-nussbaum.net>2012-04-26 10:21:33 +0200
committerLucas Nussbaum <lucas@lucas-nussbaum.net>2012-04-26 10:21:33 +0200
commitc8c32eea5d329773bda8ce0a073266ab498507c5 (patch)
tree1f6bd5bf62b826c51ed7912e9e7f3c3c5bf70694
parent04db76a10d2f26e124731f7601722bfa2de61dfe (diff)
parentd3ac1f64a5ba90d755e58bd0f3ff2813baca510b (diff)
downloadfeed2imap-c8c32eea5d329773bda8ce0a073266ab498507c5.tar.gz
feed2imap-c8c32eea5d329773bda8ce0a073266ab498507c5.tar.bz2
feed2imap-c8c32eea5d329773bda8ce0a073266ab498507c5.zip
Merge remote-tracking branch 'chimrod/master'
Diffstat (limited to '')
-rw-r--r--data/doc/feed2imap/examples/feed2imaprc1
-rw-r--r--lib/feed2imap/cache.rb26
-rw-r--r--lib/feed2imap/config.rb5
-rw-r--r--lib/feed2imap/feed2imap.rb4
-rw-r--r--lib/feed2imap/httpfetcher.rb17
-rw-r--r--lib/feed2imap/maildir.rb2
6 files changed, 31 insertions, 24 deletions
diff --git a/data/doc/feed2imap/examples/feed2imaprc b/data/doc/feed2imap/examples/feed2imaprc
index ae2f48c..7e93386 100644
--- a/data/doc/feed2imap/examples/feed2imaprc
+++ b/data/doc/feed2imap/examples/feed2imaprc
@@ -12,6 +12,7 @@
# default-email: default email address in the format foo@example.com
# disable-ssl-verification: disable SSL certification when connecting
# to IMAPS accounts (true/false)
+# timeout: time before getting timeout when fetching feeds (default 30) in seconds
#
# Per-feed options:
# name: name of the feed (must be unique)
diff --git a/lib/feed2imap/cache.rb b/lib/feed2imap/cache.rb
index 6dc0ddf..9fb9930 100644
--- a/lib/feed2imap/cache.rb
+++ b/lib/feed2imap/cache.rb
@@ -193,22 +193,16 @@ class CachedChannel
@itemstemp.unshift(j)
break
end
- end
- next if found
- if not always_new
- # Try to find an updated item
- @items.each do |j|
- # Do we need a better heuristic ?
- if j.is_ancestor_of(i)
- i.cacheditem.index = j.index
- i.cacheditem.updated = true
- updateditems.push(i)
- found = true
- # let's put j in front of itemstemp
- @itemstemp.delete(j)
- @itemstemp.unshift(i.cacheditem)
- break
- end
+ # If we didn't find exact match, try to check if we have an update
+ if j.is_ancestor_of(i)
+ i.cacheditem.index = j.index
+ i.cacheditem.updated = true
+ updateditems.push(i)
+ found = true
+ # let's put j in front of itemstemp
+ @itemstemp.delete(j)
+ @itemstemp.unshift(i.cacheditem)
+ break
end
end
next if found
diff --git a/lib/feed2imap/config.rb b/lib/feed2imap/config.rb
index 74d5507..fd4e94f 100644
--- a/lib/feed2imap/config.rb
+++ b/lib/feed2imap/config.rb
@@ -34,7 +34,7 @@ LOGNAME = Etc.getlogin
# Feed2imap configuration
class F2IConfig
- attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname, :reupload_if_updated, :parts
+ attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname, :reupload_if_updated, :parts, :timeout
# Load the configuration from the IO stream
# TODO should do some sanity check on the data read.
@@ -60,6 +60,8 @@ class F2IConfig
@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?
@@ -137,6 +139,7 @@ class ConfigFeed
@reupload_if_updated = f2iconfig.reupload_if_updated
@reupload_if_updated = f['reupload-if-updated'] if f.has_key?('reupload-if-updated')
+
end
def needfetch(lastcheck)
diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb
index b938a39..acfb56e 100644
--- a/lib/feed2imap/feed2imap.rb
+++ b/lib/feed2imap/feed2imap.rb
@@ -121,7 +121,9 @@ class Feed2Imap
end
fetch_start = Time::now
if feed.url
- s = HTTPFetcher::fetch(feed.url, @cache.get_last_check(feed.name))
+ fetcher = HTTPFetcher::new
+ fetcher::timeout = @config.timeout
+ s = fetcher::fetch(feed.url, @cache.get_last_check(feed.name))
elsif feed.execurl
# avoid running more than one command at the same time.
# We need it because the called command might not be
diff --git a/lib/feed2imap/httpfetcher.rb b/lib/feed2imap/httpfetcher.rb
index 9980578..6734465 100644
--- a/lib/feed2imap/httpfetcher.rb
+++ b/lib/feed2imap/httpfetcher.rb
@@ -34,7 +34,14 @@ HTTPDEBUG = false
# Class used to retrieve the feed over HTTP
class HTTPFetcher
- def HTTPFetcher::fetcher(baseuri, uri, lastcheck, recursion)
+
+ @timeout = 30 # should be enough for everybody...
+
+ def timeout=(value)
+ @timeout = value
+ end
+
+ def fetcher(baseuri, uri, lastcheck, recursion)
proxy_host = nil
proxy_port = nil
proxy_user = nil
@@ -50,8 +57,8 @@ class HTTPFetcher
proxy_port,
proxy_user,
proxy_pass ).new(uri.host, uri.port)
- http.read_timeout = 30 # should be enough for everybody...
- http.open_timeout = 30
+ http.read_timeout = @timeout
+ http.open_timeout = @timeout
if uri.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@@ -108,8 +115,8 @@ class HTTPFetcher
end
end
- def HTTPFetcher::fetch(url, lastcheck)
+ def fetch(url, lastcheck)
uri = URI::parse(url)
- return HTTPFetcher::fetcher(uri, uri, lastcheck, MAXREDIR)
+ return fetcher(uri, uri, lastcheck, MAXREDIR)
end
end
diff --git a/lib/feed2imap/maildir.rb b/lib/feed2imap/maildir.rb
index f05c60c..eb7c8a2 100644
--- a/lib/feed2imap/maildir.rb
+++ b/lib/feed2imap/maildir.rb
@@ -161,7 +161,7 @@ class MaildirAccount
basename = File.basename(file)
colon = basename.rindex(':')
- return (colon and basename.slice(colon + 1, -1))
+ return (colon and basename[colon + 1 .. -1])
end
# Re-written and no longer shamelessly taken from