jmcarbo-imapstore 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +15 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +74 -0
- data/Rakefile +29 -0
- data/bin/imapstore +85 -0
- data/lib/imapstore.rb +9 -0
- data/lib/imapstore/imapstore.rb +255 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/imapstore_spec.rb +72 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/tasks/rspec.rake +21 -0
- metadata +107 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
bin/imapstore
|
7
|
+
lib/imapstore.rb
|
8
|
+
lib/imapstore/imapstore.rb
|
9
|
+
script/console
|
10
|
+
script/destroy
|
11
|
+
script/generate
|
12
|
+
spec/imapstore_spec.rb
|
13
|
+
spec/spec.opts
|
14
|
+
spec/spec_helper.rb
|
15
|
+
tasks/rspec.rake
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= imapstore
|
2
|
+
|
3
|
+
* http://wiki.github.com/jmcarbo/imapstore
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
ruby gem to use an imap server as a file storage device
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* many
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
Usage: imapstore -c <ls, rm, put, get, rmdir, mkdir, quota, setup> -s <subject> -d <folder> -f <file list or glob>
|
16
|
+
imapstore -h
|
17
|
+
|
18
|
+
== REQUIREMENTS:
|
19
|
+
|
20
|
+
* IMAP account
|
21
|
+
* config file. Currently only supports this location: ~/.imapstore/config.yml
|
22
|
+
* config file sample:
|
23
|
+
|
24
|
+
email: account@gmail.com
|
25
|
+
password: password
|
26
|
+
store_tag: IMAPSTORE
|
27
|
+
imap_server: imap.gmail.com
|
28
|
+
imap_port: 993
|
29
|
+
|
30
|
+
store_tag is the tag used in the message subject to distinguish imapstore created messages from any other messages in the
|
31
|
+
store.
|
32
|
+
|
33
|
+
== INSTALL:
|
34
|
+
|
35
|
+
# add githum gem repository if you haven't done so
|
36
|
+
|
37
|
+
gem sources -a http://gems.github.com
|
38
|
+
|
39
|
+
#install gem
|
40
|
+
|
41
|
+
sudo gem install imapstore
|
42
|
+
|
43
|
+
# Create sample config at ~/.imapstore/config.yml
|
44
|
+
|
45
|
+
imapstore -c setup
|
46
|
+
|
47
|
+
# Get help
|
48
|
+
|
49
|
+
imapstore -h
|
50
|
+
|
51
|
+
== LICENSE:
|
52
|
+
|
53
|
+
(The MIT License)
|
54
|
+
|
55
|
+
Copyright (c) 2009 Joan Marc Carbo Arnau
|
56
|
+
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
58
|
+
a copy of this software and associated documentation files (the
|
59
|
+
'Software'), to deal in the Software without restriction, including
|
60
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
61
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
62
|
+
permit persons to whom the Software is furnished to do so, subject to
|
63
|
+
the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be
|
66
|
+
included in all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
69
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
70
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
71
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
72
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
73
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
74
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/imapstore'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('imapstore', IMAPSTORE::VERSION) do |p|
|
7
|
+
p.developer('Joan Marc Carbo Arnau', 'jmcarbo@gmail.com')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
#p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
p.extra_deps = [
|
12
|
+
['tmail','>= 1.2.3'],
|
13
|
+
['getoptions','>= 0.1']
|
14
|
+
]
|
15
|
+
p.extra_dev_deps = [
|
16
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
17
|
+
]
|
18
|
+
|
19
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
20
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
21
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
22
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
26
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
27
|
+
|
28
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
29
|
+
# task :default => [:spec, :features]
|
data/bin/imapstore
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'imapstore'
|
6
|
+
require 'getoptions'
|
7
|
+
|
8
|
+
COMMAND_LIST = ['ls', 'rm', 'put', 'get', 'rmdir', 'mkdir', 'quota', 'setup' ]
|
9
|
+
opt = GetOptions.new(%w(help subject=s command=s dir=s files=@s recursive! versioned! ))
|
10
|
+
|
11
|
+
if opt['help']
|
12
|
+
puts "Usage: imapstore -c <#{COMMAND_LIST.join(', ')}> -s <subject> -d <folder> -f <file list or glob> "
|
13
|
+
puts " imapstore -h"
|
14
|
+
exit 0
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
command = opt['command'] || "ls"
|
19
|
+
dir = opt['dir'] || "INBOX"
|
20
|
+
files = opt['files'] || "*"
|
21
|
+
subject = opt['subject'] || ""
|
22
|
+
recursive = opt['recursive'] || false
|
23
|
+
versioned = opt['versioned']
|
24
|
+
|
25
|
+
begin
|
26
|
+
if COMMAND_LIST.include? command
|
27
|
+
if command == 'setup'
|
28
|
+
IMAPSTORE::Imapstore.create_config_file
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
i = IMAPSTORE::Imapstore.new
|
32
|
+
i.versioned=versioned if versioned!=nil
|
33
|
+
|
34
|
+
case command
|
35
|
+
when 'ls':
|
36
|
+
files.each do |f|
|
37
|
+
f = /.+/ if f == '*'
|
38
|
+
|
39
|
+
i.ls(dir, Regexp.new(f)).each do |a|
|
40
|
+
puts a
|
41
|
+
end
|
42
|
+
end
|
43
|
+
when 'put':
|
44
|
+
files.each do |f|
|
45
|
+
Dir.glob(f) do |f2|
|
46
|
+
if(!File.directory? f2)
|
47
|
+
puts "Storing file #{f2}"
|
48
|
+
i.store_file(f2,dir,subject)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
when 'get':
|
53
|
+
files.each do |f|
|
54
|
+
f = /.+/ if f == '*'
|
55
|
+
puts "Getting files"
|
56
|
+
i.get_file(dir, Regexp.new(f)).each do |a|
|
57
|
+
puts a
|
58
|
+
end
|
59
|
+
end
|
60
|
+
when 'rm':
|
61
|
+
files.each do |f|
|
62
|
+
f = /.+/ if f == '*'
|
63
|
+
puts "Deleting files"
|
64
|
+
i.rm_file(dir, Regexp.new(f)).each do |a|
|
65
|
+
puts a
|
66
|
+
end
|
67
|
+
end
|
68
|
+
when 'mkdir':
|
69
|
+
i.mkdir(dir)
|
70
|
+
when 'rmdir':
|
71
|
+
i.rmdir(dir)
|
72
|
+
when 'quota':
|
73
|
+
q = i.quota("INBOX")
|
74
|
+
puts "Used #{q[1]['usage'].to_s} of #{q[1]['quota'].to_s}"
|
75
|
+
else
|
76
|
+
puts "unimplemented command #{command}"
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
i.disconnect
|
82
|
+
end
|
83
|
+
rescue
|
84
|
+
puts "An error has occured #{$!}"
|
85
|
+
end
|
data/lib/imapstore.rb
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
require 'net/imap'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'tmail'
|
4
|
+
require 'pp'
|
5
|
+
require 'base64'
|
6
|
+
require 'cgi'
|
7
|
+
|
8
|
+
|
9
|
+
module IMAPSTORE
|
10
|
+
class Imapstore
|
11
|
+
MAX_FILE_SIZE=20000000
|
12
|
+
CHUNK_SIZE=10000000
|
13
|
+
|
14
|
+
CONFIG_TEMPLATE = <<-END
|
15
|
+
email: account@gmail.com
|
16
|
+
password: password
|
17
|
+
store_tag: IMAPSTORE
|
18
|
+
imap_server: imap.gmail.com
|
19
|
+
imap_port: 993
|
20
|
+
END
|
21
|
+
|
22
|
+
def self.create_config_file(file = File.expand_path('~/.imapstore/config.yml'))
|
23
|
+
if !File.exists?(file)
|
24
|
+
puts "creating #{File.dirname(file)}"
|
25
|
+
FileUtils.mkdir_p(File.dirname(file))
|
26
|
+
File.open(file,"w").write(CONFIG_TEMPLATE)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize
|
31
|
+
@versioned = true
|
32
|
+
get_config
|
33
|
+
connect
|
34
|
+
end
|
35
|
+
|
36
|
+
def versioned
|
37
|
+
@versioned
|
38
|
+
end
|
39
|
+
|
40
|
+
def versioned=(is_versioned)
|
41
|
+
@versioned = is_versioned
|
42
|
+
end
|
43
|
+
|
44
|
+
def email
|
45
|
+
@email
|
46
|
+
end
|
47
|
+
|
48
|
+
def password
|
49
|
+
@password
|
50
|
+
end
|
51
|
+
|
52
|
+
def store_tag
|
53
|
+
@store_tag
|
54
|
+
end
|
55
|
+
|
56
|
+
def imap_server
|
57
|
+
@imap_server
|
58
|
+
end
|
59
|
+
|
60
|
+
def imap_port
|
61
|
+
@imap_port
|
62
|
+
end
|
63
|
+
|
64
|
+
def connect()
|
65
|
+
if !@imap && @email && @password && @imap_server && @imap_port
|
66
|
+
@imap = Net::IMAP.new(@imap_server, @imap_port, true)
|
67
|
+
@imap.login(@email, @password)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def disconnect()
|
72
|
+
if @imap
|
73
|
+
@imap.logout()
|
74
|
+
begin
|
75
|
+
@imap.disconnect()
|
76
|
+
rescue
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_config(file = File.expand_path('~/.imapstore/config.yml'))
|
82
|
+
if !File.exists?(file)
|
83
|
+
File.open(file,"w").write(CONFIG_TEMPLATE)
|
84
|
+
end
|
85
|
+
aConfig = YAML::load_file(file)
|
86
|
+
|
87
|
+
#COFIGURATION SECTION
|
88
|
+
@email = aConfig['email']
|
89
|
+
@password = aConfig['password']
|
90
|
+
@store_tag = aConfig['store_tag'] || "IMAPSTORE"
|
91
|
+
@imap_server = aConfig['imap_server']
|
92
|
+
@imap_port = aConfig['imap_port']
|
93
|
+
#END CONFIGURATION SECTION
|
94
|
+
end
|
95
|
+
|
96
|
+
def store_file_chunk( file, folder = "INBOX", subject = "", chunk=nil, chunk_no=0, max_chunk_no=0 )
|
97
|
+
if(max_chunk_no>0)
|
98
|
+
puts "Storing part #{chunk_no} of #{max_chunk_no}"
|
99
|
+
end
|
100
|
+
basename = File.basename(file)
|
101
|
+
version = 0
|
102
|
+
|
103
|
+
if max_chunk_no == 0
|
104
|
+
tag = "#{@store_tag}[#{basename}]"
|
105
|
+
else
|
106
|
+
tag = "#{@store_tag}[#{basename}](#{chunk_no}-#{max_chunk_no})"
|
107
|
+
end
|
108
|
+
@imap.select(folder)
|
109
|
+
@imap.search(["SUBJECT", tag, "NOT", "DELETED"]).each do |message_id|
|
110
|
+
if @versioned==true
|
111
|
+
version = version + 1
|
112
|
+
else
|
113
|
+
@imap.store(message_id, "+FLAGS", [:Deleted])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
@imap.expunge
|
117
|
+
|
118
|
+
mail = TMail::Mail.new
|
119
|
+
mail.to = @email
|
120
|
+
mail.from = @email
|
121
|
+
if max_chunk_no == 0
|
122
|
+
mail.subject = "#{@store_tag}[#{basename}]"
|
123
|
+
else
|
124
|
+
mail.subject = "#{@store_tag}[#{basename}](#{chunk_no}-#{max_chunk_no})"
|
125
|
+
end
|
126
|
+
|
127
|
+
if version > 0
|
128
|
+
mail.subject = mail.subject + "(v. #{version})"
|
129
|
+
end
|
130
|
+
|
131
|
+
if subject
|
132
|
+
mail.subject = mail.subject + ": #{subject}"
|
133
|
+
end
|
134
|
+
|
135
|
+
mail.date = Time.now
|
136
|
+
mail.mime_version = '1.0'
|
137
|
+
|
138
|
+
mailpart1=TMail::Mail.new
|
139
|
+
mailpart1.set_content_type 'text', 'plain'
|
140
|
+
mailpart1.body = "This is a mail storage message of file #{file}"
|
141
|
+
mail.parts << mailpart1
|
142
|
+
mail.set_content_type 'multipart', 'mixed'
|
143
|
+
|
144
|
+
if FileTest.exists?(file)
|
145
|
+
mailpart=TMail::Mail.new
|
146
|
+
mailpart.body = Base64.encode64(chunk.to_s)
|
147
|
+
mailpart.transfer_encoding="Base64"
|
148
|
+
if max_chunk_no == 0
|
149
|
+
mailpart['Content-Disposition'] = "attachment; filename=#{CGI::escape(basename)}"
|
150
|
+
else
|
151
|
+
mailpart['Content-Disposition'] = "attachment; filename=#{CGI::escape(basename)}_#{chunk_no}-#{max_chunk_no}"
|
152
|
+
end
|
153
|
+
mail.parts.push(mailpart)
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
@imap.append(folder, mail.to_s, [:Seen], File.new(file).atime)
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
def store_file( file, folder = "INBOX", subject = "")
|
162
|
+
|
163
|
+
@imap.create(folder) if !@imap.list("", folder)
|
164
|
+
|
165
|
+
size = File.size(file)
|
166
|
+
if(size > MAX_FILE_SIZE)
|
167
|
+
remaining = size
|
168
|
+
max_chunk_no = (size/CHUNK_SIZE)+1
|
169
|
+
chunk_no = 1
|
170
|
+
File.open(file) do |f|
|
171
|
+
while(remaining>0)
|
172
|
+
content = f.read(CHUNK_SIZE)
|
173
|
+
store_file_chunk( file, folder, subject, content, chunk_no, max_chunk_no)
|
174
|
+
chunk_no = chunk_no +1
|
175
|
+
remaining = remaining - CHUNK_SIZE
|
176
|
+
end
|
177
|
+
end
|
178
|
+
else
|
179
|
+
content=File.open(file).read
|
180
|
+
store_file_chunk( file, folder, subject, content)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def ls(folder = "INBOX", glob = /.+/)
|
185
|
+
if folder == "/"
|
186
|
+
return @imap.list("","*").map { |d| d.name }.sort
|
187
|
+
end
|
188
|
+
|
189
|
+
file_list = []
|
190
|
+
@imap.select(folder)
|
191
|
+
@imap.search(["NOT", "DELETED"]).each do |message_id|
|
192
|
+
a = @imap.fetch(message_id, "RFC822")
|
193
|
+
mail = TMail::Mail.parse(a[0].attr["RFC822"])
|
194
|
+
file_name = mail.subject.match(/^[^\[]+\[([^\]]+)\]/)[1]
|
195
|
+
file_list << file_name if file_name.match(glob)
|
196
|
+
end
|
197
|
+
file_list
|
198
|
+
end
|
199
|
+
|
200
|
+
def get_file(folder = "INBOX", glob = /.+/)
|
201
|
+
file_list = []
|
202
|
+
@imap.select(folder)
|
203
|
+
@imap.search(["NOT", "DELETED"]).each do |message_id|
|
204
|
+
a = @imap.fetch(message_id, "RFC822")
|
205
|
+
mail = TMail::Mail.parse(a[0].attr["RFC822"])
|
206
|
+
file_name = mail.subject.match(/^[^\[]+\[([^\]]+)\]/)[1]
|
207
|
+
if file_name.match(glob)
|
208
|
+
if mail.multipart? then
|
209
|
+
mail.parts.each do |m|
|
210
|
+
if !m.main_type
|
211
|
+
File.open(file_name,"w").write(m.body)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
file_list << file_name
|
217
|
+
end
|
218
|
+
end
|
219
|
+
file_list
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
def rm_file(folder = "INBOX", glob = /.+/)
|
225
|
+
file_list = []
|
226
|
+
|
227
|
+
@imap.select(folder)
|
228
|
+
@imap.search(["NOT", "DELETED"]).each do |message_id|
|
229
|
+
a = @imap.fetch(message_id, "RFC822")
|
230
|
+
mail = TMail::Mail.parse(a[0].attr["RFC822"])
|
231
|
+
file_name = mail.subject.match(/^[^\[]+\[([^\]]+)\]/)[1]
|
232
|
+
if glob && file_name.match(glob)
|
233
|
+
@imap.store(message_id, "+FLAGS", [:Deleted])
|
234
|
+
file_list << file_name
|
235
|
+
end
|
236
|
+
end
|
237
|
+
@imap.expunge
|
238
|
+
|
239
|
+
file_list
|
240
|
+
end
|
241
|
+
|
242
|
+
def mkdir(folder)
|
243
|
+
@imap.create(folder)
|
244
|
+
end
|
245
|
+
|
246
|
+
def rmdir(folder)
|
247
|
+
rm_file(folder)
|
248
|
+
@imap.delete(folder)
|
249
|
+
end
|
250
|
+
|
251
|
+
def quota(folder)
|
252
|
+
@imap.getquotaroot(folder)
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/imapstore.rb'}"
|
9
|
+
puts "Loading imapstore gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
# Time to add your specs!
|
4
|
+
# http://rspec.info/
|
5
|
+
describe "Configuration" do
|
6
|
+
it "Should read configuration" do
|
7
|
+
i = IMAPSTORE::Imapstore.new
|
8
|
+
|
9
|
+
i.email.should eql( 'account@gmail.com')
|
10
|
+
i.password.should eql('password')
|
11
|
+
i.store_tag.should eql('IMAPSTORE')
|
12
|
+
i.imap_server.should eql('imap.gmail.com')
|
13
|
+
i.imap_port.should eql(993)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Connection" do
|
18
|
+
|
19
|
+
it "Should connect and disconnect properly" do
|
20
|
+
i = IMAPSTORE::Imapstore.new
|
21
|
+
|
22
|
+
i.disconnect
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Store file" do
|
29
|
+
|
30
|
+
it "Should store a file" do
|
31
|
+
i = IMAPSTORE::Imapstore.new
|
32
|
+
i.store_file(File.expand_path(File.dirname(__FILE__) + "/../lib/imapstore.rb"),"ttt","Test file")
|
33
|
+
i.rm_file("ttt")
|
34
|
+
i.disconnect
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "List folder" do
|
39
|
+
it "Sholuld list a folder" do
|
40
|
+
i = IMAPSTORE::Imapstore.new
|
41
|
+
i.store_file(File.expand_path(File.dirname(__FILE__) + "/../lib/imapstore.rb"),"ttt","Test file")
|
42
|
+
i.ls("ttt").should eql(["imapstore.rb"])
|
43
|
+
i.rm_file("ttt")
|
44
|
+
i.disconnect
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "rm_file" do
|
49
|
+
it "Sholuld remove a file" do
|
50
|
+
i = IMAPSTORE::Imapstore.new
|
51
|
+
i.store_file(File.expand_path(File.dirname(__FILE__) + "/../lib/imapstore.rb"),"ttt","Test file")
|
52
|
+
i.rm_file("ttt")
|
53
|
+
i.ls("ttt").should eql([])
|
54
|
+
i.disconnect
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "mkdir" do
|
59
|
+
it "should be able to create a valid folder" do
|
60
|
+
i = IMAPSTORE::Imapstore.new
|
61
|
+
i.mkdir('blablabla')
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "rmdir" do
|
67
|
+
it "should be able to delete an existing folder" do
|
68
|
+
i = IMAPSTORE::Imapstore.new
|
69
|
+
i.mkdir('blablabla2')
|
70
|
+
i.rmdir('blablabla2')
|
71
|
+
end
|
72
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jmcarbo-imapstore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joan Marc Carbo Arnau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-08 00:00:00 -08:00
|
13
|
+
default_executable: imapstore
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: tmail
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.2.3
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: getoptions
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0.1"
|
32
|
+
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: newgem
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.1.0
|
41
|
+
version:
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: hoe
|
44
|
+
version_requirement:
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 1.8.0
|
50
|
+
version:
|
51
|
+
description: ruby gem to use an imap server as a file storage device
|
52
|
+
email:
|
53
|
+
- jmcarbo@gmail.com
|
54
|
+
executables:
|
55
|
+
- imapstore
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files:
|
59
|
+
- History.txt
|
60
|
+
- Manifest.txt
|
61
|
+
- PostInstall.txt
|
62
|
+
- README.rdoc
|
63
|
+
files:
|
64
|
+
- History.txt
|
65
|
+
- Manifest.txt
|
66
|
+
- PostInstall.txt
|
67
|
+
- README.rdoc
|
68
|
+
- Rakefile
|
69
|
+
- bin/imapstore
|
70
|
+
- lib/imapstore.rb
|
71
|
+
- lib/imapstore/imapstore.rb
|
72
|
+
- script/console
|
73
|
+
- script/destroy
|
74
|
+
- script/generate
|
75
|
+
- spec/imapstore_spec.rb
|
76
|
+
- spec/spec.opts
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- tasks/rspec.rake
|
79
|
+
has_rdoc: true
|
80
|
+
homepage: http://wiki.github.com/jmcarbo/imapstore
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options:
|
83
|
+
- --main
|
84
|
+
- README.rdoc
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: "0"
|
92
|
+
version:
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: "0"
|
98
|
+
version:
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project: imapstore
|
102
|
+
rubygems_version: 1.2.0
|
103
|
+
signing_key:
|
104
|
+
specification_version: 2
|
105
|
+
summary: ruby gem to use an imap server as a file storage device
|
106
|
+
test_files: []
|
107
|
+
|