feed2email 0.4.0 → 0.5.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: d2edf473e3d4740e4593c3c15cf7e2bb3c106815
4
- data.tar.gz: 063706f3316c3f7610fa9b361adeca02dc2ecfe3
3
+ metadata.gz: ac8af629627f99050a52d97c8c83ae87c03663c4
4
+ data.tar.gz: cfc63b86eb14679e57d8f445559b682e2edeea16
5
5
  SHA512:
6
- metadata.gz: a2780f0f6836d9071e8021bbe206c3c369a0a516d6c38f5678448dea229d00a332e206b4d8ce734569d5b933ed518b80edcb5ea2c9136e127ba33bd1fde75b5a
7
- data.tar.gz: bcc5b42264fccb8ff5e54479120c6c50d67f188ddd343b1d894bb7b810e923e9b3c1f6a4693875ee6cae387250d465f0965f4d2be5ed5cb4e5e1b7c6c662fe92
6
+ metadata.gz: 8609da85c1b80a45cc69fa03ef66abbd3b5a4d0e588a720c3700fe887fe884afacbfa33f4b975037fed7d4480a2a6b219a9bebf01273cf28b5c1e25fd75fa23e
7
+ data.tar.gz: 3434bf8b41b8a0528f215a273c337198c16986e8ad04732e27417aa2b8af3b33d268110dbf94f4592679833b63fa10fb3ae77e0da06aefb6f33f07db3eaf6dfa
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.5.0
2
+
3
+ * Sanitize SMTP user in from address
4
+ * Add config option for sender email address (from)
5
+ * Add config option for log verbosity
6
+ * Add text/plain part in email messages
7
+ * Strip HTML from email subject and body title
8
+
1
9
  ### 0.4.0
2
10
 
3
11
  * Major rewrite to keep history of processed (seen) entries
data/Gemfile.lock CHANGED
@@ -1,45 +1,33 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- feed2email (0.3.0)
4
+ feed2email (0.4.0)
5
5
  feedzirra
6
6
  mail
7
+ sanitize
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- activesupport (3.1.12)
12
- multi_json (~> 1.0)
13
- builder (3.2.2)
14
- curb (0.7.18)
15
- feedzirra (0.1.3)
16
- activesupport (~> 3.1.1)
17
- builder (>= 2.1.2)
18
- curb (~> 0.7.15)
19
- i18n (>= 0.5.0)
20
- loofah (~> 1.2.0)
21
- nokogiri (>= 1.4.4)
22
- rake (>= 0.8.7)
23
- rdoc (~> 3.8)
24
- sax-machine (~> 0.1.0)
25
- i18n (0.6.5)
26
- json (1.8.0)
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)
27
17
  loofah (1.2.1)
28
18
  nokogiri (>= 1.4.4)
29
19
  mail (2.5.4)
30
20
  mime-types (~> 1.16)
31
21
  treetop (~> 1.4.8)
32
- mime-types (1.24)
33
- mini_portile (0.5.1)
34
- multi_json (1.7.9)
35
- nokogiri (1.6.0)
22
+ mime-types (1.25.1)
23
+ mini_portile (0.5.2)
24
+ nokogiri (1.6.1)
36
25
  mini_portile (~> 0.5.0)
37
26
  polyglot (0.3.3)
38
- rake (10.1.0)
39
- rdoc (3.12.2)
40
- json (~> 1.4)
41
- sax-machine (0.1.0)
42
- nokogiri (> 0.0.0)
27
+ sanitize (2.1.0)
28
+ nokogiri (>= 1.4.4)
29
+ sax-machine (0.2.1)
30
+ nokogiri (~> 1.6.0)
43
31
  treetop (1.4.15)
44
32
  polyglot
45
33
  polyglot (>= 0.3.1)
data/README.md CHANGED
@@ -41,15 +41,23 @@ pair is separated with a colon: `foo: bar`
41
41
  ### Generic options
42
42
 
43
43
  * `recipient` (required) is the email address to send email to
44
+ * `sender` (optional) is the email address to send email from (default is taken
45
+ from the feed entry author or, if missing, it is generated from the SMTP user
46
+ and host or, if missing, it is the same as `recipient`)
44
47
  * `send_delay` (optional) is the number of seconds to wait between each email to
45
48
  avoid SMTP server throttling errors (default is `10`; use `0` to disable)
46
49
  * `log_path` (optional) is the _absolute_ path to the log file (default is
47
50
  `true` which logs to standard output; use `false` to disable)
51
+ * `log_level` (optional) is the logging verbosity level and can be `fatal`
52
+ (least verbose), `error`, `warn`, `info` (default) and `debug` (most verbose)
48
53
  * `max_entries` (optional) is the maximum number of entries to process per feed
49
54
  (default is `20`; use `0` for unlimited)
50
55
 
51
56
  ### SMTP
52
57
 
58
+ For this method you need to have access to an SMTP service. [Mailgun][] has a
59
+ free plan.
60
+
53
61
  * `smtp_host` is the SMTP service hostname to connect to
54
62
  * `smtp_port` is the SMTP service port to connect to
55
63
  * `smtp_user` is the username of your email account
@@ -63,10 +71,12 @@ your system will be able to read `config.yml` and your password. To prevent
63
71
  this, feed2email will not run and complain if it detects the wrong permissions.
64
72
  You can set the correct permissions with `chmod 600 ~/.feed2email/config.yml`.
65
73
 
74
+ [Mailgun]: http://www.mailgun.com/
75
+
66
76
  ### MTA
67
77
 
68
78
  For this method you need to have an [MTA][] with a [Sendmail][]-compatible
69
- interface setup and working in your system. I suggest [msmtp][] or [Postfix][].
79
+ interface setup and working in your system like [msmtp][] or [Postfix][].
70
80
 
71
81
  * `sendmail_path` (optional) is the path to the Sendmail binary (default is
72
82
  `/usr/sbin/sendmail`)
data/feed2email.gemspec CHANGED
@@ -23,4 +23,5 @@ Gem::Specification.new do |gem|
23
23
 
24
24
  gem.add_dependency 'feedzirra'
25
25
  gem.add_dependency 'mail'
26
+ gem.add_dependency 'sanitize'
26
27
  end
data/lib/feed2email.rb CHANGED
@@ -4,6 +4,7 @@ require 'fileutils'
4
4
  require 'logger'
5
5
  require 'mail'
6
6
  require 'net/smtp'
7
+ require 'sanitize'
7
8
  require 'singleton'
8
9
  require 'yaml'
9
10
 
@@ -2,6 +2,10 @@ class String
2
2
  def escape_html
3
3
  CGI.escapeHTML(self)
4
4
  end
5
+
6
+ def strip_html
7
+ CGI.unescapeHTML(Sanitize.clean(self))
8
+ end
5
9
  end
6
10
 
7
11
  class Time
@@ -69,6 +69,7 @@ module Feed2Email
69
69
  )
70
70
  rescue => e
71
71
  log :error, "#{e.class}: #{e.message.strip}"
72
+ e.backtrace.each {|line| log :debug, line }
72
73
  end
73
74
  end
74
75
 
@@ -107,6 +108,7 @@ module Feed2Email
107
108
  entry.process
108
109
  rescue => e
109
110
  log :error, "#{e.class}: #{e.message.strip}"
111
+ e.backtrace.each {|line| log :debug, line }
110
112
  end
111
113
 
112
114
  seen_entries << entry.uri if e.nil? # record in history if no errors
@@ -16,6 +16,10 @@ module Feed2Email
16
16
  log_path != false
17
17
  end
18
18
 
19
+ def log_level
20
+ config['log_level'] || 'info'
21
+ end
22
+
19
23
  def log_path
20
24
  config['log_path']
21
25
  end
@@ -30,7 +34,7 @@ module Feed2Email
30
34
 
31
35
  def logger
32
36
  @logger ||= ::Logger.new(log_to)
33
- @logger.level = ::Logger::INFO
37
+ @logger.level = ::Logger.const_get(log_level.upcase)
34
38
  @logger
35
39
  end
36
40
  end
@@ -8,7 +8,7 @@ module Feed2Email
8
8
  def send
9
9
  sleep config['send_delay'] || 10 # avoid Net::SMTPServerBusy errors
10
10
 
11
- if send_with_smtp?
11
+ if smtp_configured?
12
12
  send_with_smtp
13
13
  else
14
14
  send_with_sendmail
@@ -17,12 +17,7 @@ module Feed2Email
17
17
 
18
18
  private
19
19
 
20
- def body
21
- body_data = {
22
- :uri => @entry.uri.escape_html,
23
- :title => @entry.title.escape_html,
24
- :content => @entry.content,
25
- }
20
+ def body_html
26
21
  %{
27
22
  <html>
28
23
  <body>
@@ -34,52 +29,72 @@ module Feed2Email
34
29
  #{VERSION}</a> at #{Time.now}</p>
35
30
  </body>
36
31
  </html>
37
- }.gsub(/^\s+/, '') % body_data
32
+ }.gsub(/^\s+/, '') % {
33
+ :uri => @entry.uri.escape_html,
34
+ :title => @entry.title.strip_html,
35
+ :content => @entry.content,
36
+ }
38
37
  end
39
38
 
40
- def config
41
- Feed2Email::Config.instance.config
42
- end
39
+ def body_text
40
+ %{
41
+ %{title}
42
+
43
+ %{content}
43
44
 
44
- def from
45
- from_data = {
46
- :name => @feed_title,
47
- :email => from_address,
45
+ %{uri}
46
+
47
+ --
48
+ Sent by feed2email #{VERSION} at #{Time.now}
49
+ }.gsub(/^\s+/, '') % {
50
+ :title => @entry.title.strip_html,
51
+ :content => @entry.content.strip_html,
52
+ :uri => @entry.uri,
48
53
  }
49
- '"%{name}" <%{email}>' % from_data
54
+ end
55
+
56
+ def config
57
+ Feed2Email::Config.instance.config
50
58
  end
51
59
 
52
60
  def from_address
53
- if @entry.author && @entry.author['@']
61
+ if config['sender']
62
+ config['sender']
63
+ elsif @entry.author && @entry.author['@']
54
64
  @entry.author[/\S+@\S+/]
55
- elsif send_with_smtp?
65
+ elsif smtp_configured?
56
66
  '%{user}@%{host}' % {
57
- :user => config['smtp_user'],
67
+ :user => config['smtp_user'].gsub(/\W/, '_'),
58
68
  :host => config['smtp_host']
59
69
  }
60
70
  else
61
- to # recipient as a last resort
71
+ recipient
62
72
  end
63
73
  end
64
74
 
65
- def html_part
75
+ def mail
76
+ ::Mail.new.tap do |m|
77
+ m.from = %{"#{@feed_title}" <#{from_address}>}
78
+ m.to = recipient
79
+ m.subject = @entry.title.strip_html
80
+ m.html_part = mail_part('text/html', body_html)
81
+ m.text_part = mail_part('text/plain', body_text)
82
+ end.to_s
83
+ end
84
+
85
+ def mail_part(content_type, body)
66
86
  part = ::Mail::Part.new
67
- part.content_type = 'text/html; charset=UTF-8'
87
+ part.content_type = "#{content_type}; charset=UTF-8"
68
88
  part.body = body
69
89
  part
70
90
  end
71
91
 
72
- def mail
73
- ::Mail.new.tap do |m|
74
- m.from = from
75
- m.to = to
76
- m.subject = subject
77
- m.html_part = html_part
78
- end.to_s
92
+ def recipient
93
+ config['recipient']
79
94
  end
80
95
 
81
96
  def send_with_sendmail
82
- open("|#{sendmail_bin} #{to}", 'w') do |f|
97
+ open("|#{sendmail_bin} #{recipient}", 'w') do |f|
83
98
  f.write(mail)
84
99
  end
85
100
  end
@@ -95,11 +110,11 @@ module Feed2Email
95
110
  smtp = Net::SMTP.new(host, port)
96
111
  smtp.enable_starttls if tls
97
112
  smtp.start('localhost', user, pass, auth) do
98
- smtp.send_message(mail, from_address, to)
113
+ smtp.send_message(mail, from_address, recipient)
99
114
  end
100
115
  end
101
116
 
102
- def send_with_smtp?
117
+ def smtp_configured?
103
118
  config['smtp_host'] &&
104
119
  config['smtp_port'] &&
105
120
  config['smtp_user'] &&
@@ -109,13 +124,5 @@ module Feed2Email
109
124
  def sendmail_bin
110
125
  config['sendmail_path'] || '/usr/sbin/sendmail'
111
126
  end
112
-
113
- def subject
114
- @entry.title
115
- end
116
-
117
- def to
118
- config['recipient']
119
- end
120
127
  end
121
128
  end
@@ -1,3 +1,3 @@
1
1
  module Feed2Email
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feed2email
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.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: 2013-09-22 00:00:00.000000000 Z
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: feedzirra
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sanitize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: RSS/Atom feed updates in your email
42
56
  email:
43
57
  - agorf@agorf.gr
@@ -82,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
96
  version: '0'
83
97
  requirements: []
84
98
  rubyforge_project:
85
- rubygems_version: 2.0.3
99
+ rubygems_version: 2.0.14
86
100
  signing_key:
87
101
  specification_version: 4
88
102
  summary: RSS/Atom feed updates in your email