rss2mail 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3f44f1b63398c70b3ec0350c00d00e5f983df0c
4
- data.tar.gz: 620630082c4f11f38780e091c0206eed398138ce
3
+ metadata.gz: 2ab6a446362c67e63d9cb8f6df6c7944ebf57fde
4
+ data.tar.gz: 26ac3bb913287311660c844bda123d634417ce50
5
5
  SHA512:
6
- metadata.gz: abca2de4146677c09a077e4d09908f08fc36a144eb4096b3e4284defd7e8ab1602a911bf51534ba04f12d24e523113ad03a58aff8d87e1d10f57aa5a1054012e
7
- data.tar.gz: b15e68309061549f0437b6448bfdba0349e1fcdebb4a1088e8a51441a315c1a6c04495669f78fe70433f7194a57d8500ccc66a2c70724e2e27e4af5dc6a87ee4
6
+ metadata.gz: cf4cb4d6742279b979a8ac46c4118599567ec307d6fac41c9908f87762861e396c0f5da9330acf9ee2a719ddb7019028b0aafcb445da841ee6a16323e65c288c
7
+ data.tar.gz: 5760b2a4d4957335de6eb4ffa32ec4328e9c5f9cdd956320a6aac01d3c2c1dd7b5e47f530692cc17a2ea19b2d057c6173fbcba82942c3fef4771becd97402ec4
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to rss2mail version 0.2.2
5
+ This documentation refers to rss2mail version 0.3.0
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -26,7 +26,7 @@ RubyGem:: http://rubygems.org/gems/rss2mail
26
26
 
27
27
  == LICENSE AND COPYRIGHT
28
28
 
29
- Copyright (C) 2007-2013 Jens Wille
29
+ Copyright (C) 2007-2014 Jens Wille
30
30
 
31
31
  rss2mail is free software: you can redistribute it and/or modify it under
32
32
  the terms of the GNU Affero General Public License as published by the Free
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  :summary => %q{Send RSS feeds as e-mail},
11
11
  :author => %q{Jens Wille},
12
12
  :email => %q{jens.wille@gmail.com},
13
- :license => %q{AGPL},
13
+ :license => %q{AGPL-3.0},
14
14
  :homepage => :blackwinter,
15
15
  :extra_files => FileList['templates/*'].to_a,
16
16
  :dependencies => %w[nokogiri ruby-nuggets simple-rss sinatra blackwinter-unidecoder]
data/lib/rss2mail/feed.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # A component of rss2mail, the RSS to e-mail forwarder. #
5
5
  # #
6
- # Copyright (C) 2007-2013 Jens Wille #
6
+ # Copyright (C) 2007-2014 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@gmail.com> #
@@ -25,9 +25,6 @@
25
25
  #++
26
26
 
27
27
  require 'erb'
28
- require 'open3'
29
- require 'nuggets/file/which'
30
- require 'nuggets/string/evaluate'
31
28
 
32
29
  module RSS2Mail
33
30
 
@@ -35,19 +32,17 @@ module RSS2Mail
35
32
 
36
33
  include Util
37
34
 
38
- unless MAIL = File.which(mail = 'mail'.freeze)
39
- class << MAIL; self; end.send(:define_method, :to_s) { mail }
40
- end
41
-
42
- HOST = ENV['HOSTNAME'] || ENV['HOST'] || %x{hostname}.chomp.freeze
43
-
44
- FROM = "From: rss2mail@#{HOST}".freeze
45
-
46
35
  KEEP = 100
47
36
 
48
37
  def initialize(feed, options = {})
49
38
  raise TypeError, "Hash expected, got #{feed.class}" unless feed.is_a?(Hash)
50
39
 
40
+ required = [:url, :to, :title].delete_if { |key| feed.key?(key) }
41
+
42
+ unless required.empty?
43
+ raise ArgumentError, "Feed incomplete: #{required.join(', ')} missing"
44
+ end
45
+
51
46
  @feed = feed
52
47
  @simple = feed[:simple]
53
48
  @updated = feed[:updated]
@@ -56,20 +51,18 @@ module RSS2Mail
56
51
  @verbose = options[:verbose]
57
52
  @debug = options[:debug]
58
53
 
59
- required = [:url, :to, :title]
60
- required.delete_if { |key| feed.has_key?(key) }
54
+ klass, opt = transport_from(options)
55
+ @transport = "#{klass.name.split('::').last} @ #{opt}"
61
56
 
62
- unless required.empty?
63
- raise ArgumentError, "Feed incomplete: #{required.join(', ')} missing"
64
- end
57
+ extend klass
65
58
  end
66
59
 
67
60
  attr_reader :feed, :simple, :updated,
68
61
  :reload, :verbose, :debug,
69
- :content, :rss
62
+ :transport, :content, :rss
70
63
 
71
64
  def deliver(templates)
72
- raise "Mail command not found: #{MAIL}" unless MAIL
65
+ check_deliver_requirements if respond_to?(:check_deliver_requirements)
73
66
 
74
67
  if (to = Array(feed[:to])).empty?
75
68
  log 'No one to send to'
@@ -86,12 +79,11 @@ module RSS2Mail
86
79
  return
87
80
  end
88
81
 
89
- type = feed[:content_type] || 'text/html'
90
- encoding = feed[:encoding] || 'UTF-8'
91
-
92
- type_header = "Content-type: #{type}; charset=#{encoding}"
82
+ type = feed[:content_type] || 'text/html'
93
83
 
94
- unless template = templates[type[/\/(.*)/, 1]]
84
+ if template = templates[type[/\/(.*)/, 1]]
85
+ type = "Content-type: #{type}; charset=#{feed[:encoding] || 'UTF-8'}"
86
+ else
95
87
  log "Template not found: #{type}"
96
88
  return
97
89
  end
@@ -102,7 +94,7 @@ module RSS2Mail
102
94
  items.each { |item|
103
95
  link, subject, body = render(feed, item, template)
104
96
 
105
- send_mail(type_header, to, title, subject, body) {
97
+ send_mail(to, "[#{title}] #{subject}", body, type) {
106
98
  sent << link
107
99
  count += 1
108
100
  }
@@ -117,6 +109,18 @@ module RSS2Mail
117
109
 
118
110
  private
119
111
 
112
+ def transport_from(options)
113
+ if lmtp = options[:lmtp]
114
+ @lmtp = lmtp.split(':')
115
+ [Transport::LMTP, lmtp]
116
+ elsif smtp = options[:smtp]
117
+ @smtp = smtp.split(':')
118
+ [Transport::SMTP, smtp]
119
+ else
120
+ [klass = Transport::Mail, "#{klass::CMD} = #{klass::BIN.inspect}"]
121
+ end
122
+ end
123
+
120
124
  def get(reload = reload)
121
125
  conditions = {}
122
126
 
@@ -158,8 +162,8 @@ module RSS2Mail
158
162
  }
159
163
 
160
164
  log feed.values_at(:etag, :mtime, :updated).inspect, debug
161
- rescue OpenURI::HTTPError
162
- log 'Feed not found or unchanged'
165
+ rescue OpenURI::HTTPError => err
166
+ log "Feed not found or unchanged: #{err} (#{err.class})"
163
167
  rescue Exception => err
164
168
  error err, 'while getting feed'
165
169
  end
@@ -207,18 +211,14 @@ module RSS2Mail
207
211
  [link, subject, ERB.new(template).result(binding)]
208
212
  end
209
213
 
210
- def send_mail(type_header, to, title, subject, body)
214
+ def send_mail(*args)
211
215
  return if debug
212
216
 
213
- Open3.popen3(MAIL, '-e', '-a', type_header, '-a', FROM,
214
- '-s', "[#{title}] #{subject}", *to) { |mail, _, _|
215
- mail.puts body
216
- mail.close
217
- }
217
+ deliver_mail(*args)
218
218
 
219
219
  yield if block_given?
220
- rescue Errno::EPIPE, IOError => err
221
- error err, 'while sending mail', cmd
220
+ rescue Exception => err
221
+ error err, 'while sending mail', transport
222
222
  end
223
223
 
224
224
  def log(msg, verbose = verbose)
data/lib/rss2mail/rss.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # #
6
6
  # A component of rss2mail, the RSS to e-mail forwarder. #
7
7
  # #
8
- # Copyright (C) 2007-2013 Jens Wille #
8
+ # Copyright (C) 2007-2014 Jens Wille #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@gmail.com> #
@@ -56,8 +56,8 @@ module RSS2Mail
56
56
 
57
57
  def feed(*args)
58
58
  new(*args)
59
- rescue ::SimpleRSSError, ::RSS::NotWellFormedError => err
60
- yield err if block_given?
59
+ rescue Exception => err
60
+ block_given? ? yield(err) : raise
61
61
  end
62
62
 
63
63
  end
@@ -80,7 +80,11 @@ module RSS2Mail
80
80
  end
81
81
 
82
82
  def parse
83
- ::RSS::Parser.parse(content, false) || simple_parse
83
+ strict_parse || simple_parse
84
+ end
85
+
86
+ def strict_parse
87
+ ::RSS::Parser.parse(content, false)
84
88
  end
85
89
 
86
90
  def simple_parse
@@ -182,7 +186,7 @@ module RSS2Mail
182
186
 
183
187
  body.encode!(encoding) if encoding
184
188
  body
185
- rescue OpenURI::HTTPError, EOFError
189
+ rescue OpenURI::HTTPError, EOFError, SocketError
186
190
  end
187
191
 
188
192
  def extract_body(expr, attribute = nil)
@@ -0,0 +1,124 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ ###############################################################################
5
+ # #
6
+ # A component of rss2mail, the RSS to e-mail forwarder. #
7
+ # #
8
+ # Copyright (C) 2007-2014 Jens Wille #
9
+ # #
10
+ # Authors: #
11
+ # Jens Wille <jens.wille@gmail.com> #
12
+ # #
13
+ # rss2mail is free software; you can redistribute it and/or modify it under #
14
+ # the terms of the GNU Affero General Public License as published by the Free #
15
+ # Software Foundation; either version 3 of the License, or (at your option) #
16
+ # any later version. #
17
+ # #
18
+ # rss2mail is distributed in the hope that it will be useful, but WITHOUT ANY #
19
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
21
+ # more details. #
22
+ # #
23
+ # You should have received a copy of the GNU Affero General Public License #
24
+ # along with rss2mail. If not, see <http://www.gnu.org/licenses/>. #
25
+ # #
26
+ ###############################################################################
27
+ #++
28
+
29
+ module RSS2Mail
30
+
31
+ module Transport
32
+
33
+ HOST = ENV['HOSTNAME'] || ENV['HOST'] || %x{hostname}.chomp.freeze
34
+
35
+ FROM = "From: rss2mail@#{HOST}".freeze
36
+
37
+ module Mail
38
+
39
+ require 'open3'
40
+ require 'nuggets/file/which'
41
+
42
+ CMD = ENV['RSS2MAIL_MAIL_CMD'] || 'mail'.freeze
43
+
44
+ BIN = ENV['RSS2MAIL_MAIL_BIN'] || File.which(CMD)
45
+
46
+ def check_deliver_requirements
47
+ raise "Mail command not found: #{CMD}" unless BIN
48
+ end
49
+
50
+ def deliver_mail(to, subject, body, type)
51
+ Open3.popen3(
52
+ BIN, '-e',
53
+ '-a', type,
54
+ '-a', FROM,
55
+ '-s', subject,
56
+ *to
57
+ ) { |mail, _, _|
58
+ mail.puts body
59
+ }
60
+ end
61
+
62
+ end
63
+
64
+ module SMTP
65
+
66
+ require 'net/smtp'
67
+ require 'securerandom'
68
+
69
+ def deliver_mail(to, *args)
70
+ deliver_smtp(Net::SMTP, @smtp, [to], *args)
71
+ end
72
+
73
+ private
74
+
75
+ def deliver_smtp(klass, args, to, subject, body, type)
76
+ klass.start(*args) { |smtp|
77
+ to.each { |_to|
78
+ smtp.send_message(<<-EOT, FROM, *_to)
79
+ #{FROM}
80
+ To: #{Array(_to).join(', ')}
81
+ Date: #{Time.now.rfc822}
82
+ Subject: #{subject}
83
+ Message-Id: #{SecureRandom.uuid}
84
+ #{type}
85
+
86
+ #{body}
87
+ EOT
88
+ }
89
+ }
90
+ end
91
+
92
+ end
93
+
94
+ module LMTP
95
+
96
+ include SMTP
97
+
98
+ def deliver_mail(to, *args)
99
+ deliver_smtp(Net::LMTP, @lmtp, to, *args)
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
108
+ module Net
109
+
110
+ class LMTP < SMTP
111
+
112
+ # Send LMTP's LHLO command instead of SMTP's HELO command
113
+ def helo(domain)
114
+ getok("LHLO #{domain}")
115
+ end
116
+
117
+ # Send LMTP's LHLO command instead of ESMTP's EHLO command
118
+ def ehlo(domain)
119
+ getok("LHLO #{domain}")
120
+ end
121
+
122
+ end
123
+
124
+ end
@@ -3,8 +3,8 @@ module RSS2Mail
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 2
7
- TINY = 2
6
+ MINOR = 3
7
+ TINY = 0
8
8
 
9
9
  class << self
10
10
 
data/lib/rss2mail.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # #
4
4
  # rss2mail -- Send RSS feeds as e-mail #
5
5
  # #
6
- # Copyright (C) 2007-2013 Jens Wille #
6
+ # Copyright (C) 2007-2014 Jens Wille #
7
7
  # #
8
8
  # Authors: #
9
9
  # Jens Wille <jens.wille@gmail.com> #
@@ -24,9 +24,13 @@
24
24
  ###############################################################################
25
25
  #++
26
26
 
27
+ require 'rss2mail/transport'
27
28
  require 'rss2mail/util'
28
29
  require 'rss2mail/feed'
29
30
  require 'rss2mail/rss'
30
31
 
31
32
  module RSS2Mail
32
33
  end
34
+
35
+ require 'nuggets/pluggable'
36
+ Nuggets::Pluggable.load_plugins_for(RSS2Mail)
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rss2mail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-06 00:00:00.000000000 Z
11
+ date: 2014-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '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
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby-nuggets
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
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
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simple-rss
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sinatra
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: blackwinter-unidecoder
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Send RSS feeds as e-mail
@@ -90,50 +90,51 @@ extra_rdoc_files:
90
90
  - COPYING
91
91
  - ChangeLog
92
92
  files:
93
+ - COPYING
94
+ - ChangeLog
95
+ - README
96
+ - Rakefile
97
+ - bin/rss2mail
98
+ - example/config.ru
99
+ - example/feeds.yaml
93
100
  - lib/rss2mail.rb
94
101
  - lib/rss2mail/app.rb
95
102
  - lib/rss2mail/feed.rb
96
103
  - lib/rss2mail/rss.rb
104
+ - lib/rss2mail/transport.rb
97
105
  - lib/rss2mail/util.rb
98
106
  - lib/rss2mail/version.rb
99
- - bin/rss2mail
100
107
  - templates/html.erb
101
108
  - templates/plain.erb
102
- - COPYING
103
- - ChangeLog
104
- - README
105
- - Rakefile
106
- - example/config.ru
107
- - example/feeds.yaml
108
109
  homepage: http://github.com/blackwinter/rss2mail
109
110
  licenses:
110
- - AGPL
111
+ - AGPL-3.0
111
112
  metadata: {}
112
113
  post_install_message:
113
114
  rdoc_options:
114
- - --charset
115
+ - "--title"
116
+ - rss2mail Application documentation (v0.3.0)
117
+ - "--charset"
115
118
  - UTF-8
116
- - --line-numbers
117
- - --all
118
- - --title
119
- - rss2mail Application documentation (v0.2.2)
120
- - --main
119
+ - "--line-numbers"
120
+ - "--all"
121
+ - "--main"
121
122
  - README
122
123
  require_paths:
123
124
  - lib
124
125
  required_ruby_version: !ruby/object:Gem::Requirement
125
126
  requirements:
126
- - - '>='
127
+ - - ">="
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  requirements:
131
- - - '>='
132
+ - - ">="
132
133
  - !ruby/object:Gem::Version
133
134
  version: '0'
134
135
  requirements: []
135
136
  rubyforge_project:
136
- rubygems_version: 2.0.6
137
+ rubygems_version: 2.2.2
137
138
  signing_key:
138
139
  specification_version: 4
139
140
  summary: Send RSS feeds as e-mail