kindlemail 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Changelog.md +10 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +20 -0
- data/README.md +50 -0
- data/Rakefile +27 -0
- data/TODO.txt +16 -0
- data/VERSION +1 -0
- data/bin/kindlemail +4 -0
- data/conf_templates/.email_conf +11 -0
- data/conf_templates/.kindlemail +7 -0
- data/kindlemail.gemspec +75 -0
- data/lib/KindleMail.rb +135 -0
- data/lib/KindleMailFileDatastore.rb +51 -0
- data/lib/KindleMailer.rb +24 -0
- data/lib/constants.rb +23 -0
- metadata +172 -0
data/.document
ADDED
data/Changelog.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# kindlemail Changelog
|
2
|
+
|
3
|
+
### 0.1.5
|
4
|
+
* Reconfigured bin/ file to work properly with require_relative
|
5
|
+
* Changed lib/KindleMail.rb to use relative filepaths
|
6
|
+
|
7
|
+
### 0.1.4
|
8
|
+
* Restricted ruby version to >= 1.9.2
|
9
|
+
* Removed parse method from lib/KindleMail.rb
|
10
|
+
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "bundler", "~> 1.0.0"
|
10
|
+
gem "jeweler", "~> 1.5.2"
|
11
|
+
gem "gmail-mailer", "~> 0.1.1"
|
12
|
+
gem "trollop", "~> 1.16.2"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.3)
|
5
|
+
git (1.2.5)
|
6
|
+
gmail-mailer (0.1.1)
|
7
|
+
gmail_xoauth (~> 0.3.0)
|
8
|
+
mail (~> 2.2.13)
|
9
|
+
gmail_xoauth (0.3.0)
|
10
|
+
oauth (>= 0.3.6)
|
11
|
+
i18n (0.5.0)
|
12
|
+
jeweler (1.5.2)
|
13
|
+
bundler (~> 1.0.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
mail (2.2.14)
|
17
|
+
activesupport (>= 2.3.6)
|
18
|
+
i18n (>= 0.4.0)
|
19
|
+
mime-types (~> 1.16)
|
20
|
+
treetop (~> 1.4.8)
|
21
|
+
mime-types (1.16)
|
22
|
+
oauth (0.4.4)
|
23
|
+
polyglot (0.3.1)
|
24
|
+
rake (0.8.7)
|
25
|
+
treetop (1.4.9)
|
26
|
+
polyglot (>= 0.3.1)
|
27
|
+
trollop (1.16.2)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
gmail-mailer (~> 0.1.1)
|
35
|
+
jeweler (~> 1.5.2)
|
36
|
+
trollop (~> 1.16.2)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Daniel Harper
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
kindlemail is a simple way of sending personal documents to your kindle, I made this
|
2
|
+
simple application because I'm too lazy to faff about attaching items to emails and
|
3
|
+
I prefer to use the CLI.
|
4
|
+
|
5
|
+
## Notice
|
6
|
+
Users of the 3G Kindle will get charged fees for using the personal-document service so please
|
7
|
+
be aware of this, otherwise just use the Kindle in a Wifi area for free transfers.
|
8
|
+
|
9
|
+
## Your code is rubbish
|
10
|
+
I'm new to this ruby game so I'm a bit rusty on how applications are packaged up, how things are done.
|
11
|
+
I wrote this application purely for my own benefit, so if it doesn't work or you don't agree with my
|
12
|
+
code style or the way the application works, fork it and change it
|
13
|
+
(but tell me so I can be envious of people who are inevitably better than me)
|
14
|
+
|
15
|
+
## Notice 2
|
16
|
+
This is rough code and probably won't work.
|
17
|
+
|
18
|
+
## Options
|
19
|
+
|
20
|
+
kindlemail will send items to your kindle in the simplest possible manner
|
21
|
+
|
22
|
+
Valid filetypes: -
|
23
|
+
.doc - Microsoft Word
|
24
|
+
.rtf - Rich Text Format
|
25
|
+
.jpeg - JPEG image file
|
26
|
+
.jpg - JPEG image file
|
27
|
+
.gif - GIF image file
|
28
|
+
.png - PNG image file
|
29
|
+
.bmp - BMP image file
|
30
|
+
.html - Hypertext Markup Language
|
31
|
+
.htm - HyperText Markup Language
|
32
|
+
.txt - Text files
|
33
|
+
.mobi - Mobile ebooks
|
34
|
+
.prc - Mobile ebooks
|
35
|
+
.pdf - Portable Document Format (experimental)
|
36
|
+
|
37
|
+
Usage: -
|
38
|
+
kindlemail [options] <filename>
|
39
|
+
|
40
|
+
Example usage: -
|
41
|
+
kindlemail my_book.mobi
|
42
|
+
|
43
|
+
Where [options] are: -
|
44
|
+
--kindle-address, -k <s>: Overrides the default kindle address to send items to
|
45
|
+
--force, -f: Send the file regardless of whether you have sent it before
|
46
|
+
--show-history, -s: Show the history of files that have been sent using kindlemail
|
47
|
+
--clear-history, -d: Clear the history of files that have been sent using kindlemail
|
48
|
+
--version, -v: Print version and exit
|
49
|
+
--help, -h: Show this message
|
50
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "kindlemail"
|
16
|
+
gem.homepage = "http://github.com/djhworld/kindlemail"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Push documents to your kindle via the personal document service}
|
19
|
+
gem.description = %Q{Sends documents to a designated kindle address painlessly and via the CLI. No need to fumble around with clumsy attachment boxes so forth, just whack in the documents you want to send and hit enter}
|
20
|
+
gem.email = "djharperuk@gmail.com"
|
21
|
+
gem.authors = ["Daniel Harper"]
|
22
|
+
gem.required_ruby_version = '>= 1.9.2'
|
23
|
+
gem.add_dependency "gmail-mailer", "~> 0.1.1"
|
24
|
+
gem.add_dependency "trollop", "~> 1.16.2"
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
data/TODO.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Changes needed for 0.1.4
|
2
|
+
- Update to use 0.2.0 of gmail-mailer
|
3
|
+
- Fix "user configuration invalid" message to mention the user can use the -k flag
|
4
|
+
- Fix issue where the -s or -d flags cannot be used without entering a filename first (bad user experience)
|
5
|
+
- Fix email configuration file issues?
|
6
|
+
- Look into issue with problems running on 1.8
|
7
|
+
-- Issue with conf_templates
|
8
|
+
-- Issue with -h flag
|
9
|
+
- Get a virtualised ubuntu setup going to test this out
|
10
|
+
|
11
|
+
Future stuff: -
|
12
|
+
- Add flag to view default kindle address
|
13
|
+
- Add ability to use multiple kindle addresses?
|
14
|
+
- Add ability to add multiple attachments?
|
15
|
+
- Add NOTICE regarding 3G usage (users will have to pay to use the Personal Docs Service)
|
16
|
+
- Add ability for user to create .email_conf file and generate the values
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.6
|
data/bin/kindlemail
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This contains the mail credentials required to send emails using your gmail account
|
2
|
+
# uncomment the lines below and insert your details
|
3
|
+
#
|
4
|
+
smtp_server: smtp.gmail.com
|
5
|
+
smtp_port: 587
|
6
|
+
smtp_consumer_key: anonymous
|
7
|
+
smtp_consumer_secret: anonymous
|
8
|
+
smtp_oauth_token:
|
9
|
+
smtp_oauth_token_secret:
|
10
|
+
host: gmail.com
|
11
|
+
email:
|
data/kindlemail.gemspec
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{kindlemail}
|
8
|
+
s.version = "0.1.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Daniel Harper"]
|
12
|
+
s.date = %q{2011-01-13}
|
13
|
+
s.default_executable = %q{kindlemail}
|
14
|
+
s.description = %q{Sends documents to a designated kindle address painlessly and via the CLI. No need to fumble around with clumsy attachment boxes so forth, just whack in the documents you want to send and hit enter}
|
15
|
+
s.email = %q{djharperuk@gmail.com}
|
16
|
+
s.executables = ["kindlemail"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Changelog.md",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.md",
|
28
|
+
"Rakefile",
|
29
|
+
"TODO.txt",
|
30
|
+
"VERSION",
|
31
|
+
"bin/kindlemail",
|
32
|
+
"conf_templates/.email_conf",
|
33
|
+
"conf_templates/.kindlemail",
|
34
|
+
"kindlemail.gemspec",
|
35
|
+
"lib/KindleMail.rb",
|
36
|
+
"lib/KindleMailFileDatastore.rb",
|
37
|
+
"lib/KindleMailer.rb",
|
38
|
+
"lib/constants.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/djhworld/kindlemail}
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
|
+
s.summary = %q{Push documents to your kindle via the personal document service}
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
54
|
+
s.add_development_dependency(%q<gmail-mailer>, ["~> 0.1.1"])
|
55
|
+
s.add_development_dependency(%q<trollop>, ["~> 1.16.2"])
|
56
|
+
s.add_runtime_dependency(%q<gmail-mailer>, ["~> 0.1.1"])
|
57
|
+
s.add_runtime_dependency(%q<trollop>, ["~> 1.16.2"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
61
|
+
s.add_dependency(%q<gmail-mailer>, ["~> 0.1.1"])
|
62
|
+
s.add_dependency(%q<trollop>, ["~> 1.16.2"])
|
63
|
+
s.add_dependency(%q<gmail-mailer>, ["~> 0.1.1"])
|
64
|
+
s.add_dependency(%q<trollop>, ["~> 1.16.2"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
69
|
+
s.add_dependency(%q<gmail-mailer>, ["~> 0.1.1"])
|
70
|
+
s.add_dependency(%q<trollop>, ["~> 1.16.2"])
|
71
|
+
s.add_dependency(%q<gmail-mailer>, ["~> 0.1.1"])
|
72
|
+
s.add_dependency(%q<trollop>, ["~> 1.16.2"])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
data/lib/KindleMail.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require 'yaml'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'KindleMailer.rb'
|
5
|
+
require 'constants.rb'
|
6
|
+
require 'KindleMailFileDatastore.rb'
|
7
|
+
|
8
|
+
# This contains all the code needed to run the CLI application
|
9
|
+
module KindleMail
|
10
|
+
class Configuration
|
11
|
+
# Create the user framework needed to run the application
|
12
|
+
def configuration_setup
|
13
|
+
dirname = File.expand_path(USER_DIR)
|
14
|
+
if !File.exists?(dirname)
|
15
|
+
Dir.mkdir(dirname)
|
16
|
+
create_storage_dir
|
17
|
+
create_user_conf_file
|
18
|
+
create_user_email_conf_file
|
19
|
+
else
|
20
|
+
create_user_conf_file if !File.exists?(USER_CONF_FILE)
|
21
|
+
create_storage_dir if !File.exists?(File.expand_path(STORAGE_DIR))
|
22
|
+
create_user_email_conf_file if !File.exists?(EMAIL_CONF_FILE)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_storage_dir
|
27
|
+
Dir.mkdir(File.expand_path(STORAGE_DIR))
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_user_conf_file
|
31
|
+
root = File.expand_path(File.dirname(__FILE__))
|
32
|
+
root = File.expand_path("../conf_templates", root)
|
33
|
+
FileUtils.cp(File.join(root, '/.kindlemail'), USER_CONF_FILE)
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_user_email_conf_file
|
37
|
+
root = File.expand_path(File.dirname(__FILE__))
|
38
|
+
root = File.expand_path("../conf_templates", root)
|
39
|
+
FileUtils.cp(File.join(root, '/.email_conf'), USER_CONF_FILE)
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_email_credentials
|
43
|
+
raise ArgumentError, "Cannot find email credentials file #{EMAIL_CONF_FILE}." if !File.exists?(EMAIL_CONF_FILE)
|
44
|
+
YAML.load_file(EMAIL_CONF_FILE).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Application
|
49
|
+
attr_reader :cmd_parser
|
50
|
+
attr_reader :opts
|
51
|
+
def run
|
52
|
+
setup
|
53
|
+
process
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup
|
57
|
+
ban = ""
|
58
|
+
ban << "kindlemail will send items to your kindle in the simplest possible manner"
|
59
|
+
ban << "\n\nValid filetypes: -"
|
60
|
+
VALID_FILE_TYPES.each { |key,val| ban << "\n #{key} - #{val}" }
|
61
|
+
ban << "\n\nUsage: -"
|
62
|
+
ban << "\n kindlemail [options] <filename>"
|
63
|
+
ban << "\n\nExample usage: -"
|
64
|
+
ban << "\n kindlemail my_book.mobi"
|
65
|
+
ban << "\n\nWhere [options] are: -"
|
66
|
+
|
67
|
+
@opts = Trollop::options do
|
68
|
+
version VERSION_STRING
|
69
|
+
banner ban
|
70
|
+
opt :kindle_address, "Overrides the default kindle address to send items to", :short => "-k", :type => :string
|
71
|
+
opt :force, "Send the file regardless of whether you have sent it before", :short => "-f", :default => nil
|
72
|
+
opt :show_history, "Show the history of files that have been sent using kindlemail", :short => "-s", :default => nil
|
73
|
+
opt :clear_history, "Clear the history of files that have been sent using kindlemail", :short => "-d", :default => nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def process
|
78
|
+
begin
|
79
|
+
puts "\n#{VERSION_STRING}\n\n"
|
80
|
+
if ARGV.empty?
|
81
|
+
raise ArgumentError, "Please specify a file to send (or use the -h option to see help)"
|
82
|
+
end
|
83
|
+
config_manager = KindleMail::Configuration.new
|
84
|
+
config_manager.configuration_setup
|
85
|
+
|
86
|
+
mailer = KindleMailer.new(config_manager.get_email_credentials)
|
87
|
+
datastore = KindleMailFileDatastore.new
|
88
|
+
|
89
|
+
if(@opts[:show_history_given])
|
90
|
+
datastore.print_history
|
91
|
+
exit
|
92
|
+
end
|
93
|
+
|
94
|
+
if(@opts[:clear_history_given])
|
95
|
+
print "Clearing file history"
|
96
|
+
datastore.clear_history
|
97
|
+
puts "...done"
|
98
|
+
exit
|
99
|
+
end
|
100
|
+
|
101
|
+
kindle_address = ""
|
102
|
+
|
103
|
+
if(!@opts[:kindle_address_given])
|
104
|
+
# no -k flag specified, see if a configuration file has been set
|
105
|
+
if(File.exist?(USER_CONF_FILE))
|
106
|
+
config = YAML.load_file(USER_CONF_FILE).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
107
|
+
raise ArgumentError, "The configuration file #{USER_CONF_FILE} was found but appears to be invalid/incomplete.\nThe most likely reason for this is the fact that you need to set a default kindle address to send items to.\nYou must edit the file and follow the instructions in the comments before trying again. Alternatively use the -k flag to specify a kindle address to send the item to" if config.key?(:kindle_addr) == false || config[:kindle_addr].nil?
|
108
|
+
kindle_address = config[:kindle_addr]
|
109
|
+
else
|
110
|
+
raise ArgumentError, "No address has been specified to send the item to.\nEither add an address in #{USER_CONF_FILE} or use the -kindle_address (-k) option"
|
111
|
+
end
|
112
|
+
else
|
113
|
+
#User has specified the -k flag
|
114
|
+
kindle_address = @opts[:kindle_address]
|
115
|
+
end
|
116
|
+
|
117
|
+
force_send = @opts[:force_given] ? true : false
|
118
|
+
file_to_send = ARGV[0]
|
119
|
+
|
120
|
+
if(!force_send)
|
121
|
+
if(datastore.file_exists?(kindle_address, File.basename(file_to_send)))
|
122
|
+
raise ArgumentError, "This file has already been sent to #{kindle_address}. Use the --force (-f) option if you want to resend it"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
send_result = mailer.send(kindle_address, file_to_send)
|
127
|
+
datastore.add_entry(kindle_address,File.basename(file_to_send)) if send_result
|
128
|
+
|
129
|
+
rescue ArgumentError => message
|
130
|
+
puts "#{message}"
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'constants.rb'
|
2
|
+
class KindleMailFileDatastore
|
3
|
+
|
4
|
+
def load_store
|
5
|
+
if(File.exist?(FILE_STORE))
|
6
|
+
data = IO.read(FILE_STORE)
|
7
|
+
@db = Marshal.load(data)
|
8
|
+
else
|
9
|
+
@db = {}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_exists?(kindle_addr, filename)
|
14
|
+
load_store
|
15
|
+
if(@db.key?kindle_addr == false)
|
16
|
+
return false
|
17
|
+
elsif(@db[kindle_addr].nil?)
|
18
|
+
return false
|
19
|
+
elsif(@db[kindle_addr].key?filename)
|
20
|
+
puts "This file was sent to #{kindle_addr} on #{@db[kindle_addr][filename]}"
|
21
|
+
return true
|
22
|
+
end
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_entry(kindle_addr,filename)
|
27
|
+
load_store
|
28
|
+
@db[kindle_addr] = {} if(@db[kindle_addr].nil?)
|
29
|
+
@db[kindle_addr][filename] = Time.now
|
30
|
+
data = Marshal.dump(@db)
|
31
|
+
file = File.new(FILE_STORE, "w")
|
32
|
+
file.write data
|
33
|
+
file.close
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_history
|
37
|
+
load_store
|
38
|
+
if !@db.empty?
|
39
|
+
@db.each { |email, val|
|
40
|
+
puts email
|
41
|
+
val.each { |filename,sentdate| print " => " + filename + " was sent on " + sentdate.strftime("%a %d %h %H:%M:%S") + "\n" }
|
42
|
+
}
|
43
|
+
else
|
44
|
+
puts "There are no items in the history"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear_history
|
49
|
+
FileUtils.rm(FILE_STORE) if File.exist?(FILE_STORE)
|
50
|
+
end
|
51
|
+
end
|
data/lib/KindleMailer.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'gmail-mailer'
|
2
|
+
require 'constants.rb'
|
3
|
+
class KindleMailer
|
4
|
+
attr_accessor :kindle_address
|
5
|
+
attr_accessor :email_credentials
|
6
|
+
def initialize(email_credentials)
|
7
|
+
@email_credentials = email_credentials
|
8
|
+
end
|
9
|
+
|
10
|
+
def send(kindle_address, file)
|
11
|
+
@kindle_address = kindle_address
|
12
|
+
filepath = File.expand_path(file)
|
13
|
+
raise ArgumentError, "The file you have specified does not exist #{SEE_HELP}" if file.nil? || !File.exist?(filepath)
|
14
|
+
raise ArgumentError, "The file you have specified is not a valid type #{SEE_HELP}" if VALID_FILE_TYPES.include?(File.extname(file)) == false
|
15
|
+
|
16
|
+
puts "Preparing #{File.basename(filepath)} to be sent to #{@kindle_address}"
|
17
|
+
|
18
|
+
mailer = GmailMailer::Mailer.new(@email_credentials)
|
19
|
+
mailer.sendMessage(GmailMailer::Message.new(@kindle_address, "a@b.c", filepath))
|
20
|
+
|
21
|
+
puts "#{File.basename(filepath)} was successfully sent to #{@kindle_address}"
|
22
|
+
return true
|
23
|
+
end
|
24
|
+
end
|
data/lib/constants.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
VALID_FILE_TYPES = {
|
2
|
+
".doc" => "Microsoft Word",
|
3
|
+
".rtf" => "Rich Text Format",
|
4
|
+
".jpeg" => "JPEG image file",
|
5
|
+
".jpg" => "JPEG image file",
|
6
|
+
".gif" => "GIF image file",
|
7
|
+
".png" => "PNG image file",
|
8
|
+
".bmp" => "BMP image file",
|
9
|
+
".html" => "Hypertext Markup Language",
|
10
|
+
".htm" => "HyperText Markup Language",
|
11
|
+
".txt" => "Text files",
|
12
|
+
".mobi" => "Mobile ebooks",
|
13
|
+
".prc" => "Mobile ebooks",
|
14
|
+
".pdf" => "Portable Document Format (experimental)" }
|
15
|
+
SEE_HELP = "\nUse the -h flag for usage details"
|
16
|
+
USER_DIR = "~/.kindlemail"
|
17
|
+
STORAGE_DIR = USER_DIR + "/.storage"
|
18
|
+
EMAIL_CONF_FILE = File.expand_path(USER_DIR + "/.email_conf")
|
19
|
+
USER_CONF_FILE = File.expand_path(USER_DIR + "/.kindlemail")
|
20
|
+
VERSION = "0.1.6"
|
21
|
+
VERSION_STRING = "kindlemail #{VERSION} (January 2011). https://github.com/djhworld/kindlemail"
|
22
|
+
FILE_STORE = File.expand_path(STORAGE_DIR + "/sent_files.history")
|
23
|
+
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kindlemail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Daniel Harper
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-13 00:00:00 +00:00
|
18
|
+
default_executable: kindlemail
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 1.0.0
|
32
|
+
type: :development
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jeweler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 5
|
45
|
+
- 2
|
46
|
+
version: 1.5.2
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: gmail-mailer
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
- 1
|
60
|
+
- 1
|
61
|
+
version: 0.1.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: trollop
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ~>
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 1
|
74
|
+
- 16
|
75
|
+
- 2
|
76
|
+
version: 1.16.2
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: gmail-mailer
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
- 1
|
90
|
+
- 1
|
91
|
+
version: 0.1.1
|
92
|
+
type: :runtime
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: trollop
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 1
|
104
|
+
- 16
|
105
|
+
- 2
|
106
|
+
version: 1.16.2
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: *id006
|
110
|
+
description: Sends documents to a designated kindle address painlessly and via the CLI. No need to fumble around with clumsy attachment boxes so forth, just whack in the documents you want to send and hit enter
|
111
|
+
email: djharperuk@gmail.com
|
112
|
+
executables:
|
113
|
+
- kindlemail
|
114
|
+
extensions: []
|
115
|
+
|
116
|
+
extra_rdoc_files:
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.md
|
119
|
+
files:
|
120
|
+
- .document
|
121
|
+
- Changelog.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- TODO.txt
|
128
|
+
- VERSION
|
129
|
+
- bin/kindlemail
|
130
|
+
- conf_templates/.email_conf
|
131
|
+
- conf_templates/.kindlemail
|
132
|
+
- kindlemail.gemspec
|
133
|
+
- lib/KindleMail.rb
|
134
|
+
- lib/KindleMailFileDatastore.rb
|
135
|
+
- lib/KindleMailer.rb
|
136
|
+
- lib/constants.rb
|
137
|
+
has_rdoc: true
|
138
|
+
homepage: http://github.com/djhworld/kindlemail
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
segments:
|
152
|
+
- 1
|
153
|
+
- 9
|
154
|
+
- 2
|
155
|
+
version: 1.9.2
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
segments:
|
162
|
+
- 0
|
163
|
+
version: "0"
|
164
|
+
requirements: []
|
165
|
+
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 1.3.7
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: Push documents to your kindle via the personal document service
|
171
|
+
test_files: []
|
172
|
+
|