summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Nussbaum <lucas@lucas-nussbaum.net>2010-11-30 22:03:03 +0100
committerLucas Nussbaum <lucas@lucas-nussbaum.net>2010-11-30 22:03:03 +0100
commitc46c823aff3ad63fbc62c2281ac4fddb0bcb1e21 (patch)
tree13952d711e7a96ab1580c84a595c04dce89b4134
parent94dc1db641f98242496a32409e823920f4e700e9 (diff)
downloadfeed2imap-c46c823aff3ad63fbc62c2281ac4fddb0bcb1e21.tar.gz
feed2imap-c46c823aff3ad63fbc62c2281ac4fddb0bcb1e21.tar.bz2
feed2imap-c46c823aff3ad63fbc62c2281ac4fddb0bcb1e21.zip
Add a reupload_if_updated option (default: true)
Following a discussion on feed2imap-devel, add a reupload_if_updated option. When set to false, if an item is updated, but was previously removed from the IMAP server, it is no longer re-uploaded. Also fix some config file parsing bugs for the disable-ssl-verification and include-images options. I should really switch to another way to describe F2I config...
Diffstat (limited to '')
-rw-r--r--data/doc/feed2imap/examples/feed2imaprc4
-rw-r--r--lib/feed2imap/config.rb17
-rw-r--r--lib/feed2imap/feed2imap.rb2
-rw-r--r--lib/feed2imap/imap.rb5
4 files changed, 20 insertions, 8 deletions
diff --git a/data/doc/feed2imap/examples/feed2imaprc b/data/doc/feed2imap/examples/feed2imaprc
index 4fd8797..4bda33f 100644
--- a/data/doc/feed2imap/examples/feed2imaprc
+++ b/data/doc/feed2imap/examples/feed2imaprc
@@ -7,6 +7,8 @@
# debug-updated: (for debugging purposes) if true, display a lot of information
# about the "updated-items" algorithm.
# include-images: download images and include them in the mail? (true/false)
+# reupload-if-updated: when an item is updated, and was previously deleted,
+# reupload it? (true/false, default true)
# default-email: default email address in the format foo@example.com
# disable-ssl-verification: disable SSL certification when connecting
# to IMAPS accounts (true/false)
@@ -20,6 +22,8 @@
# feed will be fetched
# disable: if set to something, the feed will be ignored
# include-images: download images and include them in the mail? (true/false)
+# reupload-if-updated: when an item is updated, and was previously deleted,
+# reupload it? (true/false, default true)
# always-new: feed2imap tries to use a clever algorithm to determine whether
# an item is new or has been updated. It doesn't work well with some web apps
# like mediawiki. When this flag is enabled, all items which don't match
diff --git a/lib/feed2imap/config.rb b/lib/feed2imap/config.rb
index 53e6543..c0cdddd 100644
--- a/lib/feed2imap/config.rb
+++ b/lib/feed2imap/config.rb
@@ -33,7 +33,7 @@ LOGNAME = Etc.getlogin
# Feed2imap configuration
class F2IConfig
- attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname
+ attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname, :reupload_if_updated
# Load the configuration from the IO stream
# TODO should do some sanity check on the data read.
@@ -45,9 +45,10 @@ class F2IConfig
@feeds = []
@max_failures = (@conf['max-failures'] || 10).to_i
@updateddebug = (@conf['debug-updated'] and @conf['debug-updated'] != 'false')
- @include_images = (@conf['include-images'] and @conf['include-images'] != 'false')
+ @include_images = !(@conf.has_key?('include-images') and @conf['include-images'] != 'false')
+ @reupload_if_updated = !(@conf.has_key?('reupload-if-updated') and @conf['reupload-if-updated'] == false)
@default_email = (@conf['default-email'] || "#{LOGNAME}@#{HOSTNAME}")
- ImapAccount.no_ssl_verify = (@conf['disable-ssl-verification'] and @conf['disable-ssl-verification'] != 'false')
+ 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
maildir_account = MaildirAccount::new
@@ -94,7 +95,7 @@ end
# A configured feed. simple data container.
class ConfigFeed
- attr_reader :name, :url, :imapaccount, :folder, :always_new, :execurl, :filter, :ignore_hash, :dumpdir, :wrapto, :include_images
+ attr_reader :name, :url, :imapaccount, :folder, :always_new, :execurl, :filter, :ignore_hash, :dumpdir, :wrapto, :include_images, :reupload_if_updated
attr_accessor :body
def initialize(f, imapaccount, folder, f2iconfig)
@@ -111,8 +112,12 @@ class ConfigFeed
@dumpdir = f['dumpdir'] || nil
@wrapto = if f['wrapto'] == nil then 72 else f['wrapto'].to_i end
@include_images = f2iconfig.include_images
- if f['include-images']
- @include_images = (f['include-images'] != 'false')
+ if f.has_key?('include-images')
+ @include_images = (f['include-images'] != false)
+ end
+ @reupload_if_updated = f2iconfig.reupload_if_updated
+ if f.has_key?('reupload-if-updated')
+ @reupload_if_updated = (f['reupload-if-updated'] != false)
end
end
diff --git a/lib/feed2imap/feed2imap.rb b/lib/feed2imap/feed2imap.rb
index fb4c794..b938a39 100644
--- a/lib/feed2imap/feed2imap.rb
+++ b/lib/feed2imap/feed2imap.rb
@@ -247,7 +247,7 @@ class Feed2Imap
id = "<#{fn}-#{i.cacheditem.index}@#{@config.hostname}>"
email = item_to_mail(@config, i, id, true, f.name, f.include_images, f.wrapto)
f.imapaccount.updatemail(f.folder, email,
- id, i.date || Time::new)
+ id, i.date || Time::new, f.reupload_if_updated)
end
# reverse is needed to upload older items first (fixes gna#8986)
newitems.reverse.each do |i|
diff --git a/lib/feed2imap/imap.rb b/lib/feed2imap/imap.rb
index c4e7106..60775e2 100644
--- a/lib/feed2imap/imap.rb
+++ b/lib/feed2imap/imap.rb
@@ -108,7 +108,7 @@ class ImapAccount
end
# update a mail
- def updatemail(folder, mail, id, date = Time::now)
+ def updatemail(folder, mail, id, date = Time::now, reupload_if_updated = true)
create_folder_if_not_exists(folder)
@connection.select(folder)
searchres = @connection.search(['HEADER', 'Message-Id', id])
@@ -119,6 +119,9 @@ class ImapAccount
searchres.each { |m| @connection.store(m, "+FLAGS", [:Deleted]) }
@connection.expunge
flags -= [ :Recent ] # avoids errors with dovecot
+ elsif not reupload_if_updated
+ # mail not present, and we don't want to re-upload it
+ return
end
@connection.append(folder, mail.gsub(/\n/, "\r\n"), flags, date)
end