feed2email 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +62 -17
- data/bin/feed2email +1 -6
- data/lib/feed2email.rb +1 -0
- data/lib/feed2email/feed.rb +35 -13
- data/lib/feed2email/mail.rb +44 -11
- data/lib/feed2email/version.rb +1 -1
- metadata +8 -3
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ RSS/Atom feed updates in your email
|
|
6
6
|
|
7
7
|
I don't like having a separate application for feeds when I'm already checking my email. I also never read a thing when feeds are kept in a separate place.
|
8
8
|
|
9
|
-
|
9
|
+
feed2email was written primarily as a replacement of [rss2email][] and aims to be simpler, faster, smaller and easier to use.
|
10
10
|
|
11
11
|
[rss2email]: http://www.allthingsrss.com/rss2email/
|
12
12
|
|
@@ -18,37 +18,82 @@ Install as a [gem][] from [RubyGems][]:
|
|
18
18
|
$ gem install feed2email
|
19
19
|
~~~
|
20
20
|
|
21
|
-
You also need to have [Sendmail][] working in your system to send mail. I use [msmtp][] which is a nice alternative with a compatible Sendmail interface.
|
22
|
-
|
23
21
|
[gem]: http://rubygems.org/gems/feed2email
|
24
22
|
[RubyGems]: http://rubygems.org/
|
25
|
-
[Sendmail]: http://en.wikipedia.org/wiki/Sendmail
|
26
|
-
[msmtp]: http://msmtp.sourceforge.net/
|
27
23
|
|
28
|
-
##
|
24
|
+
## Configuration
|
29
25
|
|
30
|
-
|
26
|
+
Since version 0.2.0, feed2email no longer supports command-line arguments and is configured through a [YAML][] configuration file located under `~/.feed2email/config.yml`.
|
31
27
|
|
32
|
-
|
28
|
+
There are two ways to send mail: SMTP and Sendmail. If `config.yml` contains options for both, feed2email will use SMTP.
|
33
29
|
|
34
|
-
|
35
|
-
* `~/.feed2email/state.yml` is created containing the timestamp of when each feed was last fetched
|
30
|
+
[YAML]: http://en.wikipedia.org/wiki/YAML
|
36
31
|
|
37
|
-
|
32
|
+
### SMTP
|
38
33
|
|
39
|
-
|
34
|
+
Since version 0.2.0, it is possible to send mail via SMTP.
|
40
35
|
|
41
|
-
|
42
|
-
|
36
|
+
Here's a sample `config.yml` file:
|
37
|
+
|
38
|
+
~~~ yaml
|
39
|
+
recipient: johndoe@example.org
|
40
|
+
smtp_host: mail.example.org
|
41
|
+
smtp_port: 587
|
42
|
+
smtp_user: johndoe
|
43
|
+
smtp_pass: 12345
|
44
|
+
smtp_tls: true
|
45
|
+
smtp_auth: login
|
43
46
|
~~~
|
44
47
|
|
45
|
-
|
48
|
+
A short explanation of the available options:
|
49
|
+
|
50
|
+
* `recipient` is the email address to send updates to
|
51
|
+
* `smtp_host` is the SMTP service hostname to connect to
|
52
|
+
* `smtp_port` is the SMTP service port to connect to
|
53
|
+
* `smtp_user` is the username of your mail account
|
54
|
+
* `smtp_pass` is the password of your mail account (see the warning below)
|
55
|
+
* `smtp_tls` (optional) controls TLS (default is `true`; can also be `false`)
|
56
|
+
* `smtp_auth` (optional) controls the authentication method (default is `login`; can also be `plain` or `cram_md5`)
|
57
|
+
|
58
|
+
**Warning:** Unless it has correct restricted permissions, anyone with access in your system will be able to read `config.yml` and your password. To prevent this, feed2email will not run and complain if it detects the wrong permissions. You can set the correct permissions with `chmod 600 ~/.feed2email/config.yml`.
|
59
|
+
|
60
|
+
### Sendmail
|
61
|
+
|
62
|
+
For this method you need to have [Sendmail][] setup and working in your system. It is also possible to use [a program with a Sendmail-compatible interface][msmtp].
|
63
|
+
|
64
|
+
Assuming you have everything setup and working, here's a sample `config.yml` file:
|
65
|
+
|
66
|
+
~~~ yaml
|
67
|
+
recipient: johndoe@example.org
|
68
|
+
sendmail_path: /usr/sbin/sendmail
|
69
|
+
~~~
|
70
|
+
|
71
|
+
A short explanation of the available options:
|
72
|
+
|
73
|
+
* `recipient` is the email address to send updates to
|
74
|
+
* `sendmail_path` (optional) is the path to the Sendmail binary (default is `/usr/sbin/sendmail`)
|
75
|
+
|
76
|
+
[Sendmail]: http://en.wikipedia.org/wiki/Sendmail
|
77
|
+
[msmtp]: http://msmtp.sourceforge.net/
|
78
|
+
|
79
|
+
## Use
|
80
|
+
|
81
|
+
Create `~/.feed2email/feeds.yml` and add the address of each feed you want to subscribe to, prefixed with a dash and a space.
|
82
|
+
|
83
|
+
Then run it:
|
46
84
|
|
47
85
|
~~~ sh
|
48
|
-
$
|
86
|
+
$ feed2email
|
49
87
|
~~~
|
50
88
|
|
51
|
-
|
89
|
+
When run for the first time, feed2email enters "dry run" mode and exits almost immediately. During dry run mode:
|
90
|
+
|
91
|
+
* No feeds are fetched and, thus, no email is sent (existing feed entries are considered already seen)
|
92
|
+
* `~/.feed2email/state.yml` is created containing the timestamp of when each feed was last fetched
|
93
|
+
|
94
|
+
If you want to receive existing entries from a specific feed, you can manually alter the timestamp for that feed in `state.yml` to a value in the past. Next time you run feed2email, all entries published past that timestamp will be sent with email.
|
95
|
+
|
96
|
+
You can use [cron][] to run feed2email automatically e.g. once every hour.
|
52
97
|
|
53
98
|
[cron]: http://en.wikipedia.org/wiki/Cron
|
54
99
|
|
data/bin/feed2email
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
if %w{-h --help}.include?(ARGV[0]) || (ARGV[0].nil? && ENV['MAILTO'].nil?)
|
4
|
-
$stderr.puts "usage: #{$0} <recipient>"
|
5
|
-
exit 1
|
6
|
-
end
|
7
|
-
|
8
3
|
require 'feed2email'
|
9
4
|
|
10
|
-
Feed2Email::Feed.process_all
|
5
|
+
Feed2Email::Feed.process_all
|
data/lib/feed2email.rb
CHANGED
data/lib/feed2email/feed.rb
CHANGED
@@ -1,29 +1,51 @@
|
|
1
1
|
module Feed2Email
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
CONFIG_DIR = File.expand_path('~/.feed2email')
|
3
|
+
CONFIG_FILE = File.join(CONFIG_DIR, 'config.yml')
|
4
|
+
FEEDS_FILE = File.join(CONFIG_DIR, 'feeds.yml')
|
5
|
+
STATE_FILE = File.join(CONFIG_DIR, 'state.yml')
|
6
|
+
USER_AGENT = "feed2email/#{VERSION}"
|
5
7
|
|
6
8
|
class Feed
|
7
|
-
def self.process(uri
|
8
|
-
Feed.new(uri
|
9
|
+
def self.process(uri)
|
10
|
+
Feed.new(uri).process
|
9
11
|
end
|
10
12
|
|
11
|
-
def self.process_all
|
12
|
-
FileUtils.mkdir_p(
|
13
|
+
def self.process_all
|
14
|
+
FileUtils.mkdir_p(CONFIG_DIR)
|
15
|
+
|
16
|
+
$config = YAML.load(open(CONFIG_FILE)) rescue nil
|
17
|
+
|
18
|
+
if !$config.is_a? Hash
|
19
|
+
$stderr.puts "Error: missing or invalid config file #{CONFIG_FILE}"
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
if '%o' % (File.stat(CONFIG_FILE).mode & 0777) != '600'
|
24
|
+
$stderr.puts "Error: invalid permissions for config file #{CONFIG_FILE}"
|
25
|
+
exit 2
|
26
|
+
end
|
27
|
+
|
28
|
+
if $config['recipient'].nil?
|
29
|
+
$stderr.puts "Error: recipient missing from config file #{CONFIG_FILE}"
|
30
|
+
exit 3
|
31
|
+
end
|
32
|
+
|
33
|
+
feed_uris = YAML.load(open(FEEDS_FILE)) rescue nil
|
34
|
+
|
35
|
+
if !feed_uris.is_a? Array
|
36
|
+
$stderr.puts "Error: missing or invalid feeds file #{FEEDS_FILE}"
|
37
|
+
exit 4
|
38
|
+
end
|
13
39
|
|
14
40
|
@@fetch_times = YAML.load(open(STATE_FILE)) rescue {}
|
15
41
|
|
16
|
-
feed_uris
|
17
|
-
feed_uris.each {|uri| Feed.process(uri, options) }
|
42
|
+
feed_uris.each {|uri| Feed.process(uri) }
|
18
43
|
|
19
44
|
open(STATE_FILE, 'w') {|f| f.write(@@fetch_times.to_yaml) }
|
20
45
|
end
|
21
46
|
|
22
|
-
|
23
|
-
|
24
|
-
def initialize(uri, options)
|
47
|
+
def initialize(uri)
|
25
48
|
@uri = uri
|
26
|
-
@options = options
|
27
49
|
end
|
28
50
|
|
29
51
|
def fetch_time
|
data/lib/feed2email/mail.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
module Feed2Email
|
2
|
-
SENDMAIL = ENV['SENDMAIL'] || '/usr/sbin/sendmail'
|
3
|
-
|
4
2
|
class Mail
|
5
3
|
def initialize(entry)
|
6
4
|
@entry = entry
|
7
5
|
end
|
8
6
|
|
7
|
+
def send
|
8
|
+
if $config['smtp_host'] &&
|
9
|
+
$config['smtp_port'] &&
|
10
|
+
$config['smtp_user'] &&
|
11
|
+
$config['smtp_pass']
|
12
|
+
send_with_smtp
|
13
|
+
else
|
14
|
+
send_with_sendmail
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
9
20
|
def body
|
10
21
|
body_data = {
|
11
22
|
:uri => @entry.uri.escape_html,
|
@@ -29,14 +40,17 @@ module Feed2Email
|
|
29
40
|
def from
|
30
41
|
from_data = {
|
31
42
|
:name => @entry.feed.title,
|
32
|
-
:email =>
|
43
|
+
:email => from_address,
|
33
44
|
}
|
45
|
+
'"%{name}" <%{email}>' % from_data
|
46
|
+
end
|
34
47
|
|
35
|
-
|
36
|
-
|
48
|
+
def from_address
|
49
|
+
if @entry.author && @entry.author['@']
|
50
|
+
@entry.author
|
51
|
+
else
|
52
|
+
to
|
37
53
|
end
|
38
|
-
|
39
|
-
'"%{name}" <%{email}>' % from_data
|
40
54
|
end
|
41
55
|
|
42
56
|
def html_part
|
@@ -52,21 +66,40 @@ module Feed2Email
|
|
52
66
|
m.to = to
|
53
67
|
m.subject = subject
|
54
68
|
m.html_part = html_part
|
55
|
-
end
|
69
|
+
end.to_s
|
56
70
|
end
|
57
71
|
|
58
|
-
def
|
59
|
-
open("|#{
|
72
|
+
def send_with_sendmail
|
73
|
+
open("|#{sendmail_bin} #{to}", 'w') do |f|
|
60
74
|
f.write(mail)
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
78
|
+
def send_with_smtp
|
79
|
+
host = $config['smtp_host']
|
80
|
+
port = $config['smtp_port']
|
81
|
+
user = $config['smtp_user']
|
82
|
+
pass = $config['smtp_pass']
|
83
|
+
tls = $config['smtp_tls'] || $config['smtp_tls'].nil? # on by default
|
84
|
+
auth = ($config['smtp_auth'] || 'login').to_sym # login by default
|
85
|
+
|
86
|
+
smtp = Net::SMTP.new(host, port)
|
87
|
+
smtp.enable_starttls if tls
|
88
|
+
smtp.start('localhost', user, pass, auth) do
|
89
|
+
smtp.send_message(mail, from_address, to)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def sendmail_bin
|
94
|
+
$config['sendmail_path'] || '/usr/sbin/sendmail'
|
95
|
+
end
|
96
|
+
|
64
97
|
def subject
|
65
98
|
@entry.title
|
66
99
|
end
|
67
100
|
|
68
101
|
def to
|
69
|
-
|
102
|
+
$config['recipient']
|
70
103
|
end
|
71
104
|
end
|
72
105
|
end
|
data/lib/feed2email/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feed2email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: feedzirra
|
@@ -79,12 +79,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
79
|
- - ! '>='
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
hash: 2515505025282581014
|
82
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
86
|
none: false
|
84
87
|
requirements:
|
85
88
|
- - ! '>='
|
86
89
|
- !ruby/object:Gem::Version
|
87
90
|
version: '0'
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
hash: 2515505025282581014
|
88
94
|
requirements: []
|
89
95
|
rubyforge_project:
|
90
96
|
rubygems_version: 1.8.23
|
@@ -92,4 +98,3 @@ signing_key:
|
|
92
98
|
specification_version: 3
|
93
99
|
summary: RSS/Atom feed updates in your email
|
94
100
|
test_files: []
|
95
|
-
has_rdoc:
|