feed2email 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ require 'mail'
2
+ require 'net/smtp'
3
+
1
4
  module Feed2Email
2
5
  class Mail
3
6
  def initialize(entry, feed_title)
@@ -6,8 +9,6 @@ module Feed2Email
6
9
  end
7
10
 
8
11
  def send
9
- sleep config['send_delay'] || 10 # avoid Net::SMTPServerBusy errors
10
-
11
12
  if smtp_configured?
12
13
  send_with_smtp
13
14
  else
@@ -30,15 +31,15 @@ module Feed2Email
30
31
  </body>
31
32
  </html>
32
33
  }.gsub(/^\s+/, '') % {
33
- :uri => @entry.uri.escape_html,
34
- :title => @entry.title.strip_html,
35
- :content => @entry.content,
34
+ content: @entry.content,
35
+ title: @entry.title.strip_html,
36
+ uri: @entry.uri.escape_html,
36
37
  }
37
38
  end
38
39
 
39
40
  def body_text
40
41
  %{
41
- %{title}
42
+ # [%{title}](%{uri})
42
43
 
43
44
  %{content}
44
45
 
@@ -47,35 +48,20 @@ module Feed2Email
47
48
  --
48
49
  Sent by feed2email #{VERSION} at #{Time.now}
49
50
  }.gsub(/^\s+/, '') % {
50
- :title => @entry.title.strip_html,
51
- :content => @entry.content.strip_html,
52
- :uri => @entry.uri,
51
+ content: @entry.content.to_markdown,
52
+ title: @entry.title.strip_html,
53
+ uri: @entry.uri,
53
54
  }
54
55
  end
55
56
 
56
57
  def config
57
- Feed2Email::Config.instance.config
58
- end
59
-
60
- def from_address
61
- if config['sender']
62
- config['sender']
63
- elsif @entry.author && @entry.author['@']
64
- @entry.author[/\S+@\S+/]
65
- elsif smtp_configured?
66
- '%{user}@%{host}' % {
67
- :user => config['smtp_user'].gsub(/\W/, '_'),
68
- :host => config['smtp_host']
69
- }
70
- else
71
- recipient
72
- end
58
+ Feed2Email.config # delegate
73
59
  end
74
60
 
75
61
  def mail
76
62
  ::Mail.new.tap do |m|
77
- m.from = %{"#{@feed_title}" <#{from_address}>}
78
- m.to = recipient
63
+ m.from = %{"#{@feed_title}" <#{config['sender']}>}
64
+ m.to = config['recipient']
79
65
  m.subject = @entry.title.strip_html
80
66
  m.html_part = mail_part('text/html', body_html)
81
67
  m.text_part = mail_part('text/plain', body_text)
@@ -89,28 +75,23 @@ module Feed2Email
89
75
  part
90
76
  end
91
77
 
92
- def recipient
93
- config['recipient']
94
- end
95
-
96
78
  def send_with_sendmail
97
- open("|#{sendmail_bin} #{recipient}", 'w') do |f|
79
+ open("|#{config['sendmail_path']} #{config['recipient']}", 'w') do |f|
98
80
  f.write(mail)
99
81
  end
100
82
  end
101
83
 
102
84
  def send_with_smtp
103
- host = config['smtp_host']
104
- port = config['smtp_port']
105
- user = config['smtp_user']
106
- pass = config['smtp_pass']
107
- tls = config['smtp_tls'].nil? ? true : config['smtp_tls'] # default: true
108
- auth = (config['smtp_auth'] || 'login').to_sym # default: 'login'
109
-
110
- smtp = Net::SMTP.new(host, port)
111
- smtp.enable_starttls if tls
112
- smtp.start('localhost', user, pass, auth) do
113
- smtp.send_message(mail, from_address, recipient)
85
+ smtp = Net::SMTP.new(config['smtp_host'], config['smtp_port'])
86
+ smtp.enable_starttls if config['smtp_tls']
87
+
88
+ smtp.start(
89
+ 'localhost',
90
+ config['smtp_user'],
91
+ config['smtp_pass'],
92
+ config['smtp_auth'].to_sym
93
+ ) do
94
+ smtp.send_message(mail, config['sender'], config['recipient'])
114
95
  end
115
96
  end
116
97
 
@@ -120,9 +101,5 @@ module Feed2Email
120
101
  config['smtp_user'] &&
121
102
  config['smtp_pass']
122
103
  end
123
-
124
- def sendmail_bin
125
- config['sendmail_path'] || '/usr/sbin/sendmail'
126
- end
127
104
  end
128
105
  end
@@ -1,3 +1,3 @@
1
1
  module Feed2Email
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/feed2email.rb CHANGED
@@ -1,17 +1,18 @@
1
- require 'cgi'
2
- require 'feedzirra'
3
- require 'fileutils'
4
- require 'logger'
5
- require 'mail'
6
- require 'net/smtp'
7
- require 'sanitize'
8
- require 'singleton'
9
- require 'yaml'
1
+ module Feed2Email
2
+ CONFIG_DIR = File.expand_path('~/.feed2email')
3
+
4
+ def self.config
5
+ @config ||= Config.new(File.join(CONFIG_DIR, 'config.yml'))
6
+ end
7
+
8
+ def self.logger
9
+ @logger ||= Logger.new(config['log_path'], config['log_level'])
10
+ end
11
+
12
+ def self.log(*args)
13
+ logger.log(*args) # delegate
14
+ end
15
+ end
10
16
 
11
17
  require 'feed2email/config'
12
18
  require 'feed2email/logger'
13
- require 'feed2email/version'
14
- require 'feed2email/core_ext'
15
- require 'feed2email/mail'
16
- require 'feed2email/entry'
17
- require 'feed2email/feed'
metadata CHANGED
@@ -1,102 +1,202 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feed2email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aggelos Orfanakos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-18 00:00:00.000000000 Z
11
+ date: 2015-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: feedzirra
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.7.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.7.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: mail
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.5.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.5.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sanitize
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 2.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: reverse_markdown
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.0
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - '>='
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: fuubar
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: travis-lint
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
53
137
  - !ruby/object:Gem::Version
54
138
  version: '0'
55
- description: RSS/Atom feed updates in your email
56
- email:
57
- - agorf@agorf.gr
139
+ description:
140
+ email: me@agorf.gr
58
141
  executables:
142
+ - feed2email-migrate-history
59
143
  - feed2email
60
144
  extensions: []
61
145
  extra_rdoc_files: []
62
146
  files:
63
- - .gitignore
64
147
  - CHANGELOG.md
65
- - Gemfile
66
- - Gemfile.lock
67
148
  - LICENSE.txt
68
149
  - README.md
69
- - Rakefile
150
+ - TODO.md
70
151
  - bin/feed2email
71
- - feed2email.gemspec
152
+ - bin/feed2email-migrate-history
72
153
  - lib/feed2email.rb
73
154
  - lib/feed2email/config.rb
74
155
  - lib/feed2email/core_ext.rb
75
156
  - lib/feed2email/entry.rb
76
157
  - lib/feed2email/feed.rb
158
+ - lib/feed2email/feed_data_file.rb
159
+ - lib/feed2email/feed_history.rb
160
+ - lib/feed2email/feed_meta.rb
161
+ - lib/feed2email/feeds.rb
77
162
  - lib/feed2email/logger.rb
78
163
  - lib/feed2email/mail.rb
79
164
  - lib/feed2email/version.rb
80
- homepage: http://github.com/agorf/feed2email
81
- licenses: []
165
+ homepage: https://github.com/agorf/feed2email
166
+ licenses:
167
+ - MIT
82
168
  metadata: {}
83
- post_install_message:
169
+ post_install_message: |2+
170
+
171
+ WARNING! feed2email now maintains a separate history file per feed!
172
+
173
+ Please run the provided migration script `feed2email-migrate-history` before
174
+ using feed2email. This will split an existing single history file to many small
175
+ ones, one for each feed.
176
+
177
+ If history is not migrated, feed2email will think it is run for the first time
178
+ and will treat all entries as old (thus no email will be sent and you may miss
179
+ some entries).
180
+
181
+ WARNING! "sender" is now a required config option. Please update your config
182
+ file by setting it to an email address to send email from.
183
+
84
184
  rdoc_options: []
85
185
  require_paths:
86
186
  - lib
87
187
  required_ruby_version: !ruby/object:Gem::Requirement
88
188
  requirements:
89
- - - '>='
189
+ - - ">="
90
190
  - !ruby/object:Gem::Version
91
191
  version: '0'
92
192
  required_rubygems_version: !ruby/object:Gem::Requirement
93
193
  requirements:
94
- - - '>='
194
+ - - ">="
95
195
  - !ruby/object:Gem::Version
96
196
  version: '0'
97
197
  requirements: []
98
198
  rubyforge_project:
99
- rubygems_version: 2.0.14
199
+ rubygems_version: 2.2.2
100
200
  signing_key:
101
201
  specification_version: 4
102
202
  summary: RSS/Atom feed updates in your email
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- *.yml
3
- .bundle
4
- pkg/
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,39 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- feed2email (0.4.0)
5
- feedzirra
6
- mail
7
- sanitize
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- curb (0.8.5)
13
- feedzirra (0.7.0)
14
- curb (~> 0.8.1)
15
- loofah (~> 1.2.1)
16
- sax-machine (~> 0.2.1)
17
- loofah (1.2.1)
18
- nokogiri (>= 1.4.4)
19
- mail (2.5.4)
20
- mime-types (~> 1.16)
21
- treetop (~> 1.4.8)
22
- mime-types (1.25.1)
23
- mini_portile (0.5.2)
24
- nokogiri (1.6.1)
25
- mini_portile (~> 0.5.0)
26
- polyglot (0.3.3)
27
- sanitize (2.1.0)
28
- nokogiri (>= 1.4.4)
29
- sax-machine (0.2.1)
30
- nokogiri (~> 1.6.0)
31
- treetop (1.4.15)
32
- polyglot
33
- polyglot (>= 0.3.1)
34
-
35
- PLATFORMS
36
- ruby
37
-
38
- DEPENDENCIES
39
- feed2email!
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require 'bundler/gem_tasks'
data/feed2email.gemspec DELETED
@@ -1,27 +0,0 @@
1
- require 'date'
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'feed2email/version'
6
-
7
- Gem::Specification.new do |gem|
8
- gem.name = 'feed2email'
9
- gem.version = Feed2Email::VERSION
10
-
11
- gem.authors = ['Aggelos Orfanakos']
12
- gem.date = Date.today
13
- gem.email = ['agorf@agorf.gr']
14
- gem.homepage = 'http://github.com/agorf/feed2email'
15
-
16
- gem.description = %q{RSS/Atom feed updates in your email}
17
- gem.summary = gem.description
18
-
19
- gem.files = `git ls-files`.split($/)
20
- gem.executables = gem.files.grep(%r{^bin/}).map {|f| File.basename(f) }
21
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
- gem.require_paths = ['lib']
23
-
24
- gem.add_dependency 'feedzirra'
25
- gem.add_dependency 'mail'
26
- gem.add_dependency 'sanitize'
27
- end