kindlemail 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,7 +3,7 @@ simple application because I'm too lazy to faff about attaching items to emails
3
3
  I prefer to use the CLI.
4
4
 
5
5
  ## Information
6
- This will only work with Ruby 1.9 or greater (it has been tested on 1.9.2 specifically)
6
+ This has been tested on ruby 1.9.2 and has had cursory testing on 1.8.7
7
7
 
8
8
  ## Notice
9
9
  **DISCLAIMER** Users of the 3G Kindle will get charged fees for using the personal-document service so please
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
data/kindlemail.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kindlemail}
8
- s.version = "0.2.6"
8
+ s.version = "0.2.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Harper"]
@@ -41,13 +41,14 @@ Gem::Specification.new do |s|
41
41
  s.homepage = %q{http://github.com/djhworld/kindlemail}
42
42
  s.licenses = ["MIT"]
43
43
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.4.2}
44
+ s.rubygems_version = %q{1.3.7}
45
45
  s.summary = %q{Push documents to your kindle via the personal document service}
46
46
  s.test_files = [
47
47
  "test/test_kindle_mailer.rb"
48
48
  ]
49
49
 
50
50
  if s.respond_to? :specification_version then
51
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
52
  s.specification_version = 3
52
53
 
53
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
data/lib/KindleMail.rb CHANGED
@@ -18,11 +18,13 @@ module KindleMail
18
18
  if !File.exists?(dirname)
19
19
  Dir.mkdir(dirname)
20
20
  create_storage_dir
21
+ create_staging_dir
21
22
  create_user_conf_file
22
23
  create_user_email_conf_file
23
24
  else
24
25
  create_user_conf_file if !File.exists?(USER_CONF_FILE)
25
26
  create_storage_dir if !File.exists?(File.expand_path(STORAGE_DIR))
27
+ create_staging_dir if !File.exists?(File.expand_path(STAGING_DIR))
26
28
  create_user_email_conf_file if !File.exists?(EMAIL_CONF_FILE)
27
29
  end
28
30
  end
@@ -31,6 +33,10 @@ module KindleMail
31
33
  Dir.mkdir(File.expand_path(STORAGE_DIR))
32
34
  end
33
35
 
36
+ def create_staging_dir
37
+ Dir.mkdir(File.expand_path(STAGING_DIR))
38
+ end
39
+
34
40
  def create_user_conf_file
35
41
  root = File.expand_path(File.dirname(__FILE__))
36
42
  root = File.expand_path("../conf_templates", root)
data/lib/KindleMailer.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'gmail-mailer'
2
+ require 'fileutils'
3
+ require 'digest/md5'
2
4
  require 'constants.rb'
3
5
  class KindleMailer
4
6
  attr_accessor :kindle_address
@@ -16,8 +18,13 @@ class KindleMailer
16
18
  filepath = File.expand_path(file)
17
19
  validate_file_path(filepath)
18
20
 
21
+
19
22
  puts "Preparing #{File.basename(filepath)} to be sent to #{@kindle_address}"
20
23
 
24
+ if(File.extname(filepath).eql?(".mobi"))
25
+ filepath = stage_file(filepath)
26
+ end
27
+
21
28
  message = GmailMailer::Message.new(@kindle_address)
22
29
  message.add_attachment(filepath)
23
30
 
@@ -25,9 +32,11 @@ class KindleMailer
25
32
  mailer.send(message)
26
33
  rescue
27
34
  raise
35
+ ensure
36
+ FileUtils.rm(filepath) if(File.extname(filepath).eql?(".mobi"))
28
37
  end
29
38
 
30
- puts "#{File.basename(filepath)} was successfully sent to #{@kindle_address}"
39
+ puts "#{File.basename(file)} was successfully sent to #{@kindle_address}"
31
40
  return true
32
41
  end
33
42
 
@@ -42,4 +51,15 @@ class KindleMailer
42
51
  raise ArgumentError, "#{addr} does not appear to be a valid kindle address" if !addr.end_with?("@kindle.com")
43
52
  return true
44
53
  end
54
+
55
+ def stage_file(filepath)
56
+ new_filename=create_filename(filepath)
57
+ new_location = File.expand_path(STAGING_DIR + "/" + new_filename)
58
+ FileUtils.cp(filepath, new_location)
59
+ new_location
60
+ end
61
+
62
+ def create_filename(file)
63
+ new_filename = Digest::MD5.file(file).to_s+"_"+rand(1000000).to_s+File.extname(file)
64
+ end
45
65
  end
data/lib/constants.rb CHANGED
@@ -15,6 +15,7 @@ VALID_FILE_TYPES = {
15
15
  SEE_HELP = "\nUse the -h flag for usage details"
16
16
  USER_DIR = "~/.kindlemail"
17
17
  STORAGE_DIR = USER_DIR + "/.storage"
18
+ STAGING_DIR = USER_DIR + "/.staging"
18
19
  EMAIL_CONF_FILE = File.expand_path(USER_DIR + "/.email_conf")
19
20
  USER_CONF_FILE = File.expand_path(USER_DIR + "/.kindlemail")
20
21
 
@@ -28,3 +29,4 @@ AUTHOR = "djhworld"
28
29
  VERSION_STRING = "kindlemail #{APP_VERSION}. Written by #{AUTHOR}. #{HOMEPAGE}"
29
30
  FILE_STORE = File.expand_path(STORAGE_DIR + "/sent_files.history")
30
31
 
32
+
@@ -12,7 +12,7 @@ class TestKindleMailer < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_send_with_nil_kindle_address
15
- assert_raise(ArgumentError) { @mailer.send(nil, "file") }
15
+ assert_raise(ArgumentError) { @mailer.send(nil, "file.txt") }
16
16
  end
17
17
 
18
18
  def test_validate_kindle_address_with_nil_addr
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kindlemail
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 2
9
- - 6
10
- version: 0.2.6
8
+ - 7
9
+ version: 0.2.7
11
10
  platform: ruby
12
11
  authors:
13
12
  - Daniel Harper
@@ -19,101 +18,95 @@ date: 2011-01-17 00:00:00 +00:00
19
18
  default_executable: kindlemail
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
21
  name: bundler
24
- type: :development
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ requirement: &id001 !ruby/object:Gem::Requirement
26
23
  none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
30
- hash: 23
31
27
  segments:
32
28
  - 1
33
29
  - 0
34
30
  - 0
35
31
  version: 1.0.0
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
32
+ type: :development
38
33
  prerelease: false
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
39
36
  name: jeweler
40
- type: :development
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
42
38
  none: false
43
39
  requirements:
44
40
  - - ~>
45
41
  - !ruby/object:Gem::Version
46
- hash: 7
47
42
  segments:
48
43
  - 1
49
44
  - 5
50
45
  - 2
51
46
  version: 1.5.2
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
47
+ type: :development
54
48
  prerelease: false
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
55
51
  name: gmail-mailer
56
- type: :development
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
58
53
  none: false
59
54
  requirements:
60
55
  - - "="
61
56
  - !ruby/object:Gem::Version
62
- hash: 5
63
57
  segments:
64
58
  - 0
65
59
  - 4
66
60
  - 5
67
61
  version: 0.4.5
68
- requirement: *id003
69
- - !ruby/object:Gem::Dependency
62
+ type: :development
70
63
  prerelease: false
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
71
66
  name: trollop
72
- type: :development
73
- version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ requirement: &id004 !ruby/object:Gem::Requirement
74
68
  none: false
75
69
  requirements:
76
70
  - - ~>
77
71
  - !ruby/object:Gem::Version
78
- hash: 83
79
72
  segments:
80
73
  - 1
81
74
  - 16
82
75
  - 2
83
76
  version: 1.16.2
84
- requirement: *id004
85
- - !ruby/object:Gem::Dependency
77
+ type: :development
86
78
  prerelease: false
79
+ version_requirements: *id004
80
+ - !ruby/object:Gem::Dependency
87
81
  name: gmail-mailer
88
- type: :runtime
89
- version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ requirement: &id005 !ruby/object:Gem::Requirement
90
83
  none: false
91
84
  requirements:
92
85
  - - "="
93
86
  - !ruby/object:Gem::Version
94
- hash: 5
95
87
  segments:
96
88
  - 0
97
89
  - 4
98
90
  - 5
99
91
  version: 0.4.5
100
- requirement: *id005
101
- - !ruby/object:Gem::Dependency
92
+ type: :runtime
102
93
  prerelease: false
94
+ version_requirements: *id005
95
+ - !ruby/object:Gem::Dependency
103
96
  name: trollop
104
- type: :runtime
105
- version_requirements: &id006 !ruby/object:Gem::Requirement
97
+ requirement: &id006 !ruby/object:Gem::Requirement
106
98
  none: false
107
99
  requirements:
108
100
  - - ~>
109
101
  - !ruby/object:Gem::Version
110
- hash: 83
111
102
  segments:
112
103
  - 1
113
104
  - 16
114
105
  - 2
115
106
  version: 1.16.2
116
- requirement: *id006
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: *id006
117
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
118
111
  email: djharperuk@gmail.com
119
112
  executables:
@@ -156,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
149
  requirements:
157
150
  - - ">="
158
151
  - !ruby/object:Gem::Version
159
- hash: 3
152
+ hash: 2549843167680941989
160
153
  segments:
161
154
  - 0
162
155
  version: "0"
@@ -165,14 +158,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
158
  requirements:
166
159
  - - ">="
167
160
  - !ruby/object:Gem::Version
168
- hash: 3
169
161
  segments:
170
162
  - 0
171
163
  version: "0"
172
164
  requirements: []
173
165
 
174
166
  rubyforge_project:
175
- rubygems_version: 1.4.2
167
+ rubygems_version: 1.3.7
176
168
  signing_key:
177
169
  specification_version: 3
178
170
  summary: Push documents to your kindle via the personal document service