feed2imap 1.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ Date: Mon, 12 Aug 2013 16:25:20 +0200
2
+ From: Antonio Terceiro <terceiro@debian.org>
3
+ To: terceiro@debian.org
4
+ Subject: UTF-8 data: =?iso-8859-1?B?4ent8/o=?=
5
+ Message-ID: <regular-message-id@debian.org>
6
+ MIME-Version: 1.0
7
+ Content-Type: text/plain; charset=us-ascii
8
+ Content-Disposition: inline
9
+ User-Agent: Mutt/1.5.21 (2010-09-15)
10
+
11
+ This is a sample email
@@ -0,0 +1,11 @@
1
+ Date: Mon, 12 Aug 2013 16:25:20 +0200
2
+ From: Antonio Terceiro <terceiro@debian.org>
3
+ To: terceiro@debian.org
4
+ Subject: UTF-8 data: =?iso-8859-1?B?4ent8/o=?=
5
+ Message-ID: <regular-message-id-2@debian.org>
6
+ MIME-Version: 1.0
7
+ Content-Type: text/plain; charset=us-ascii
8
+ Content-Disposition: inline
9
+ User-Agent: Mutt/1.5.21 (2010-09-15)
10
+
11
+ This is a sample email
@@ -0,0 +1,11 @@
1
+ Date: Mon, 12 Aug 2013 16:52:17 +0200
2
+ From: Antonio Terceiro <terceiro@debian.org>
3
+ To: terceiro@debian.org
4
+ Subject: an unread message
5
+ Message-ID: <unread-message-id@debian.org>
6
+ MIME-Version: 1.0
7
+ Content-Type: text/plain; charset=us-ascii
8
+ Content-Disposition: inline
9
+ User-Agent: Mutt/1.5.21 (2010-09-15)
10
+
11
+ This message was not read yet
@@ -0,0 +1,11 @@
1
+ Date: Mon, 12 Aug 2013 17:07:02 +0200
2
+ From: Antonio Terceiro <terceiro@debian.org>
3
+ To: terceiro@debian.org
4
+ Subject: a flagged message
5
+ Message-ID: <flagged-message-id@debian.org>
6
+ MIME-Version: 1.0
7
+ Content-Type: text/plain; charset=us-ascii
8
+ Content-Disposition: inline
9
+ User-Agent: Mutt/1.5.21 (2010-09-15)
10
+
11
+ This message is flagged.
@@ -0,0 +1,11 @@
1
+ Date: Mon, 12 Aug 2013 17:08:19 +0200
2
+ From: Antonio Terceiro <terceiro@debian.org>
3
+ To: terceiro@debian.org
4
+ Subject: a new message
5
+ Message-ID: <new-message-id@debian.org>
6
+ MIME-Version: 1.0
7
+ Content-Type: text/plain; charset=us-ascii
8
+ Content-Disposition: inline
9
+ User-Agent: Mutt/1.5.21 (2010-09-15)
10
+
11
+ This message is new
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'test/unit'
6
+ require 'feed2imap/cache'
7
+ require 'feedparser'
8
+ require 'pp'
9
+
10
+ class ItemCacheTest < Test::Unit::TestCase
11
+ def test_create
12
+ cache = ItemCache::new
13
+ assert(! cache.nil?)
14
+ end
15
+
16
+ def test_cache_lastcheck
17
+ cache = ItemCache::new
18
+ assert_equal(Time::at(0), cache.get_last_check('coucou'))
19
+ t = Time::now
20
+ cache.set_last_check('coucou', t)
21
+ assert_equal(t, cache.get_last_check('coucou'))
22
+ end
23
+
24
+ def test_cache_management
25
+ c = ItemCache::new
26
+ assert_equal(0, c.nbchannels)
27
+ assert_equal(0, c.nbitems)
28
+ i1 = FeedParser::FeedItem::new
29
+ i1.title = 'title1'
30
+ i1.link = 'link1'
31
+ i1.content = 'content1'
32
+ i2 = FeedParser::FeedItem::new
33
+ i2.title = 'title2'
34
+ i2.link = 'link2'
35
+ i2.content = 'content2'
36
+ i3 = FeedParser::FeedItem::new
37
+ i3.title = 'title3'
38
+ i3.link = 'link3'
39
+ i3.content = 'content3'
40
+ assert_equal([i1, i2], c.get_new_items('id', [i1, i2])[0])
41
+ c.commit_cache('id')
42
+ assert_equal(2, c.nbitems)
43
+ assert_equal([i3], c.get_new_items('id', [i2, i3])[0])
44
+ end
45
+
46
+ def test_cache_management_updated
47
+ c = ItemCache::new
48
+ assert_equal(0, c.nbchannels)
49
+ assert_equal(0, c.nbitems)
50
+ i1 = FeedParser::FeedItem::new
51
+ i1.title = 'title1'
52
+ i1.link = 'link1'
53
+ i1.content = 'content1'
54
+ i2 = FeedParser::FeedItem::new
55
+ i2.title = 'title2'
56
+ i2.link = 'link2'
57
+ i2.content = 'content2'
58
+ news = c.get_new_items('id', [i1, i2])[0]
59
+ assert_equal([i1, i2], news)
60
+ idx1 = i1.cacheditem.index
61
+ assert_equal(0, idx1)
62
+ idx2 = i2.cacheditem.index
63
+ assert_equal(1, idx2)
64
+ c.commit_cache('id')
65
+ i3 = FeedParser::FeedItem::new
66
+ i3.title = 'title 1 - updated'
67
+ i3.link = 'link1'
68
+ i3.content = 'content1'
69
+ news, updated = c.get_new_items('id', [i3])
70
+ assert_equal([], news)
71
+ assert_equal([i3], updated)
72
+ assert_equal(idx1, i3.cacheditem.index)
73
+ i4 = FeedParser::FeedItem::new
74
+ i4.title = 'title 1 - updated'
75
+ i4.link = 'link1'
76
+ i4.content = 'content1 - modified'
77
+ news, updated = c.get_new_items('id', [i4])
78
+ assert_equal([], news)
79
+ assert_equal([i4], updated)
80
+ assert_equal(idx1, i4.cacheditem.index)
81
+ end
82
+ end
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/ruby -w
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'test/unit'
6
+ require 'feed2imap/config'
7
+ require 'stringio'
8
+
9
+ CONF1 = <<EOF
10
+ cache: /home/lucas/.feed2imap_cachedatabase
11
+ feeds:
12
+ - name: feed1
13
+ url: http://something
14
+ target: imap://login:pasword@ezaezae/Feeds/A
15
+ - name: feed2
16
+ url: http://something2
17
+ target: imap://login:pasword@ezaezae/Feeds/B
18
+ EOF
19
+ CONF2 = <<EOF
20
+ feeds:
21
+ - name: feed1
22
+ url: http://something
23
+ target: imap://login:pasword@ezaezae/Feeds/A
24
+ - name: feed2
25
+ url: http://something2
26
+ target: imaps://login:pasword@ezaezae/Feeds/B
27
+ EOF
28
+ CONFFEED = <<EOF
29
+ feeds:
30
+ - name: feed1
31
+ url: feed:http://something
32
+ target: imap://login:pasword@ezaezae/Feeds/A
33
+ - name: feed2
34
+ url: http://something2
35
+ target: imaps://login:pasword@ezaezae/Feeds/B
36
+ EOF
37
+ CONFPARTS = <<EOF
38
+ parts: text
39
+ include-images: false
40
+ feeds:
41
+ - name: feed1
42
+ url: http://something
43
+ target: imap://login:pasword@ezaezae/Feeds/A
44
+ - name: feed2
45
+ url: http://something2
46
+ target: imap://login:pasword@ezaezae/Feeds/B
47
+ EOF
48
+ CONFARRAYTARGET = <<EOF
49
+ parts: text
50
+ include-images: false
51
+ prefix: &target "maildir:///tmp/Maildir/"
52
+ feeds:
53
+ - name: feed1
54
+ url: http://something
55
+ target: [ *target, "feed1" ]
56
+ EOF
57
+ CONFINTNAME = <<EOF
58
+ parts: text
59
+ include-images: false
60
+ prefix: &target "maildir:///tmp/Maildir/"
61
+ feeds:
62
+ - name: 10
63
+ url: http://something
64
+ target: [ *target, "feed1" ]
65
+ EOF
66
+
67
+ class ConfigTest < Test::Unit::TestCase
68
+ def test_cache
69
+ sio = StringIO::new CONF1
70
+ conf = F2IConfig::new(sio)
71
+ assert_equal('/home/lucas/.feed2imap_cachedatabase', conf.cache)
72
+ # testing default value
73
+ sio = StringIO::new CONF2
74
+ conf = F2IConfig::new(sio)
75
+ assert_equal(ENV['HOME'] + '/.feed2imap.cache', conf.cache)
76
+ end
77
+
78
+ def test_accounts
79
+ sio = StringIO::new CONF1
80
+ conf = F2IConfig::new(sio)
81
+ assert_equal(1, conf.imap_accounts.length)
82
+ sio = StringIO::new CONF2
83
+ conf = F2IConfig::new(sio)
84
+ assert_equal(2, conf.imap_accounts.length)
85
+ end
86
+
87
+ def test_feedurls
88
+ sio = StringIO::new CONFFEED
89
+ conf = F2IConfig::new(sio)
90
+ assert_equal('http://something', conf.feeds[0].url)
91
+ assert_equal('http://something2', conf.feeds[1].url)
92
+ end
93
+
94
+ def test_parts
95
+ sio = StringIO::new CONFPARTS
96
+ conf = F2IConfig::new(sio)
97
+ assert conf.parts.include?('text')
98
+ assert ! conf.parts.include?('html')
99
+ end
100
+
101
+ def test_url_array
102
+ sio = StringIO::new CONFARRAYTARGET
103
+ conf = F2IConfig::new(sio)
104
+ assert_equal "/tmp/Maildir/feed1", conf.feeds.first.folder
105
+ end
106
+
107
+ def test_integer_as_name
108
+ sio = StringIO.new CONFINTNAME
109
+ conf = F2IConfig.new(sio)
110
+ assert_equal "10", conf.feeds.first.name
111
+ end
112
+
113
+ end
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+
5
+ require 'test/unit'
6
+ require 'feed2imap/httpfetcher'
7
+
8
+ class HttpFetcherTest < Test::Unit::TestCase
9
+ def test_get_https
10
+ s = ''
11
+ assert_nothing_raised do
12
+ s = fetcher.fetch('https://linuxfr.org/pub/', Time::at(0))
13
+ end
14
+ assert(s.length > 20)
15
+ end
16
+
17
+ def test_get_http
18
+
19
+ end
20
+
21
+ def test_get_httpnotmodif
22
+ s = 'aaa'
23
+ assert_nothing_raised do
24
+ s = fetcher.fetch('http://www.lucas-nussbaum.net/feed2imap_tests/notmodified.php', Time::new())
25
+ end
26
+ assert_nil(s)
27
+ end
28
+
29
+ def test_get_redir1
30
+ s = 'aaa'
31
+ assert_nothing_raised do
32
+ s = fetcher.fetch("http://www.lucas-nussbaum.net/feed2imap_tests/redir.php?redir=#{MAXREDIR}", Time::at(0))
33
+ end
34
+ assert_equal('OK', s)
35
+ end
36
+
37
+ def test_get_redir2
38
+ s = ''
39
+ assert_raise(RuntimeError) do
40
+ s = fetcher.fetch("http://www.lucas-nussbaum.net/feed2imap_tests/redir.php?redir=#{MAXREDIR + 1}", Time::at(0))
41
+ end
42
+ end
43
+
44
+ def test_httpauth
45
+ s = ''
46
+ assert_nothing_raised do
47
+ s = fetcher.fetch("http://aaa:bbb@ensilinx1.imag.fr/~lucas/f2i_redirauth.php", Time::at(0))
48
+ end
49
+ assert_equal("Login: aaa / Password: bbb \n", s)
50
+ end
51
+
52
+ def test_redirauth
53
+ s = ''
54
+ assert_nothing_raised do
55
+ s = fetcher.fetch("http://aaa:bbb@ensilinx1.imag.fr/~lucas/f2i_redirauth.php?redir=1", Time::at(0))
56
+ end
57
+ assert_equal("Login: aaa / Password: bbb \n", s)
58
+ end
59
+
60
+ def test_notfound
61
+ s = ''
62
+ assert_raises(RuntimeError) do
63
+ s = fetcher.fetch("http://ensilinx1.imag.fr/~lucas/notfound.html", Time::at(0))
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ def fetcher
70
+ HTTPFetcher.new
71
+ end
72
+ end
@@ -0,0 +1,97 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+ require 'tmpdir'
4
+ require 'mocha/setup'
5
+
6
+ require 'feed2imap/maildir'
7
+
8
+ class TestMaildir < Test::Unit::TestCase
9
+
10
+ def setup
11
+ @tmpdirs = []
12
+ end
13
+
14
+ def teardown
15
+ @tmpdirs.each do |dir|
16
+ FileUtils.rm_rf(dir)
17
+ end
18
+ end
19
+
20
+ def test_cleanup
21
+ folder = create_maildir
22
+ msgs = message_count(folder)
23
+
24
+ four_days_ago = Time.now - (4 * 24 * 60 * 60)
25
+ old_message = Dir.glob(File.join(folder, '**/*:2,S')).first
26
+ FileUtils.touch old_message, mtime: four_days_ago
27
+
28
+ maildir_account.cleanup(folder)
29
+
30
+ assert_equal msgs - 1, message_count(folder)
31
+ end
32
+
33
+ def test_putmail
34
+ folder = create_maildir
35
+ msgs = message_count(folder)
36
+
37
+ mail = RMail::Message.new
38
+ mail.header['Subject'] = 'a message I just created'
39
+ mail.body = 'to test maildir'
40
+ maildir_account.putmail(folder, mail)
41
+
42
+ assert_equal msgs + 1, message_count(folder)
43
+ end
44
+
45
+ def test_updatemail
46
+ folder = create_maildir
47
+ path = maildir_account.send(
48
+ :find_mails,
49
+ folder,
50
+ 'regular-message-id@debian.org'
51
+ ).first
52
+ assert_not_nil path
53
+ mail = RMail::Message.new
54
+ mail.header['Subject'] = 'a different subject'
55
+ mail.header['Message-ID'] = 'regular-message-id@debian.org'
56
+ mail.body = 'This is the body of the message'
57
+ maildir_account.updatemail(folder, mail, 'regular-message-id@debian.org')
58
+
59
+ updated_path = maildir_account.send(
60
+ :find_mails,
61
+ folder,
62
+ 'regular-message-id@debian.org'
63
+ ).first
64
+ updated_mail = RMail::Parser.read(File.open(File.join(folder, updated_path)))
65
+
66
+ assert_equal 'a different subject', updated_mail.header['Subject']
67
+ end
68
+
69
+ def test_find_mails
70
+ folder = create_maildir
71
+ assert_equal 0, maildir_account.send(:find_mails, folder, 'SomeRandomMessageID').size
72
+ end
73
+
74
+ private
75
+
76
+ def create_maildir
77
+ parent = Dir.mktmpdir
78
+ @tmpdirs << parent
79
+ FileUtils.cp_r('test/maildir', parent)
80
+ return File.join(parent, 'maildir')
81
+ end
82
+
83
+ def message_count(folder)
84
+ Dir.glob(File.join(folder, '**', '*')).reject { |f| File.directory?(f) }.size
85
+ end
86
+
87
+ def maildir_account
88
+ @maildir_account ||=
89
+ begin
90
+ MaildirAccount.new.tap do |account|
91
+ account.stubs(:puts)
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: feed2imap
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.6
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Nussbaum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-feedparser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ description: RSS/Atom feed aggregator
28
+ email:
29
+ executables:
30
+ - feed2imap
31
+ - feed2imap-cleaner
32
+ - feed2imap-dumpconfig
33
+ - feed2imap-opmlimport
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - COPYING
38
+ - ChangeLog
39
+ - README
40
+ - Rakefile
41
+ - bin/feed2imap
42
+ - bin/feed2imap-cleaner
43
+ - bin/feed2imap-dumpconfig
44
+ - bin/feed2imap-opmlimport
45
+ - data/doc/feed2imap/examples/feed2imaprc
46
+ - data/man/man1/feed2imap-cleaner.1
47
+ - data/man/man1/feed2imap-dumpconfig.1
48
+ - data/man/man1/feed2imap-opmlimport.1
49
+ - data/man/man1/feed2imap.1
50
+ - data/man/man5/feed2imaprc.5
51
+ - lib/feed2imap.rb
52
+ - lib/feed2imap/cache.rb
53
+ - lib/feed2imap/config.rb
54
+ - lib/feed2imap/feed2imap.rb
55
+ - lib/feed2imap/html2text-parser.rb
56
+ - lib/feed2imap/httpfetcher.rb
57
+ - lib/feed2imap/imap.rb
58
+ - lib/feed2imap/itemtomail.rb
59
+ - lib/feed2imap/maildir.rb
60
+ - lib/feed2imap/rexml_patch.rb
61
+ - lib/feed2imap/sgml-parser.rb
62
+ - lib/feed2imap/version.rb
63
+ - setup.rb
64
+ - test/maildir/cur/1376317520.15784_1.debian:2,S
65
+ - test/maildir/cur/1376317520.15789_1.debian:2,S
66
+ - test/maildir/cur/1376319137.17850_1.debian:2,
67
+ - test/maildir/cur/1376320022.18396_5.debian:2,FS
68
+ - test/maildir/new/1376320099.18396_7.debian
69
+ - test/tc_cache.rb
70
+ - test/tc_config.rb
71
+ - test/tc_httpfetcher.rb
72
+ - test/tc_maildir.rb
73
+ homepage:
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.2.5
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: RSS/Atom feed aggregator
95
+ test_files: []