imapstore 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2009-01-07
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
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
@@ -0,0 +1,7 @@
1
+
2
+ For more information on imapstore, see http://imapstore.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,96 @@
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
+ == USAGE
10
+
11
+ * recursive storing files
12
+
13
+ imapstore -c put -r -d <folder> -f <files>
14
+
15
+ * snipplets
16
+
17
+ imapstore -c snipplet -s <subject> -d <folder> -t <text>
18
+
19
+ * verbose output
20
+
21
+ -x
22
+
23
+ * select imap account
24
+
25
+ -i <account in config.yml>
26
+
27
+ == FEATURES/PROBLEMS:
28
+
29
+ * many
30
+
31
+ == SYNOPSIS:
32
+
33
+ Usage: imapstore -c <ls, rm, put, get, rmdir, mkdir, quota, setup> -s <subject> -d <folder> -f <file list or glob>
34
+ imapstore -h
35
+
36
+ == REQUIREMENTS:
37
+
38
+ * IMAP account
39
+ * config file. Currently only supports this location: ~/.imapstore/config.yml
40
+ * config file sample:
41
+
42
+ email: account@gmail.com
43
+ password: password
44
+ store_tag: IMAPSTORE
45
+ imap_server: imap.gmail.com
46
+ imap_port: 993
47
+
48
+ store_tag is the tag used in the message subject to distinguish imapstore created messages from any other messages in the
49
+ store.
50
+
51
+ == INSTALL:
52
+
53
+ # First make sure you have the latest version of gem
54
+
55
+ gem update --system
56
+
57
+ # add githum gem repository if you haven't done so
58
+
59
+ gem sources -a http://gems.github.com
60
+
61
+ #install gem
62
+
63
+ sudo gem install imapstore
64
+
65
+ # Create sample config at ~/.imapstore/config.yml
66
+
67
+ imapstore -c setup
68
+
69
+ # Get help
70
+
71
+ imapstore -h
72
+
73
+ == LICENSE:
74
+
75
+ (The MIT License)
76
+
77
+ Copyright (c) 2009 Joan Marc Carbo Arnau
78
+
79
+ Permission is hereby granted, free of charge, to any person obtaining
80
+ a copy of this software and associated documentation files (the
81
+ 'Software'), to deal in the Software without restriction, including
82
+ without limitation the rights to use, copy, modify, merge, publish,
83
+ distribute, sublicense, and/or sell copies of the Software, and to
84
+ permit persons to whom the Software is furnished to do so, subject to
85
+ the following conditions:
86
+
87
+ The above copyright notice and this permission notice shall be
88
+ included in all copies or substantial portions of the Software.
89
+
90
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
91
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
92
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
93
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
94
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
95
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
96
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
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
+ ['rdoc','>= 2.2.0'],
13
+ ['tmail','>= 1.2.3'],
14
+ ['getoptions','>= 0.1']
15
+ ]
16
+ p.extra_dev_deps = [
17
+ ['newgem', ">= #{::Newgem::VERSION}"]
18
+ ]
19
+
20
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
21
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
22
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
23
+ p.rsync_args = '-av --delete --ignore-errors'
24
+ end
25
+
26
+ require 'newgem/tasks' # load /tasks/*.rake
27
+ Dir['tasks/**/*.rake'].each { |t| load t }
28
+
29
+ # TODO - want other tests/tasks run by default? Add them to the list
30
+ # task :default => [:spec, :features]
data/bin/imapstore ADDED
@@ -0,0 +1,119 @@
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
+ #old versions of ruby require this
8
+ require 'rdoc/ri/ri_paths'
9
+
10
+ COMMAND_LIST = ['ls', 'rm', 'put', 'get', 'rmdir', 'mkdir', 'quota', 'setup', 'snipplet' ]
11
+ opt = GetOptions.new(%w( help subject=s command=s dir=s files=@s recursive! versioned! all! imapstore:s x! text=s))
12
+
13
+ if opt['help']
14
+ puts "Usage: imapstore -c <#{COMMAND_LIST.join(', ')}> -s <subject> -d <folder> -f <file list or glob> "
15
+ puts " -i <imapstore> -x --recursive --versioned --all"
16
+ puts " imapstore -h"
17
+ exit 0
18
+ end
19
+
20
+ imapstore = opt['imapstore'] || "default"
21
+ command = opt['command'] || "ls"
22
+ dir = opt['dir'] || "INBOX"
23
+ files = opt['files'] || "*"
24
+ subject = opt['subject'] || ""
25
+ recursive = opt['recursive'] || false
26
+ all = opt['all'] || false
27
+ versioned = opt['versioned']
28
+ verbose = opt['x'] || false
29
+ text = opt['text'] || "no text"
30
+
31
+
32
+
33
+
34
+ begin
35
+
36
+ if COMMAND_LIST.include? command
37
+ if command == 'setup'
38
+ IMAPSTORE::Imapstore.create_config_file
39
+ exit
40
+ end
41
+
42
+ puts "Opening mailstore #{imapstore} configured in #{File.expand_path('~/.imapstore/config.yml')}" if verbose
43
+ i = IMAPSTORE::Imapstore.new(File.expand_path('~/.imapstore/config.yml'), imapstore)
44
+ puts "Mailstore #{imapstore} opened" if verbose
45
+
46
+ i.versioned=versioned if versioned!=nil
47
+ i.verbose = verbose
48
+
49
+ puts "Executing command #{command}" if verbose
50
+ case command
51
+ when 'ls':
52
+ files.each do |f|
53
+ f = /.+/ if f == '*'
54
+
55
+ i.ls(dir, Regexp.new(f), recursive, all).each do |a|
56
+ puts a
57
+ end
58
+ end
59
+ when 'put':
60
+ puts "Storing files" if verbose
61
+ files.each do |f|
62
+ f = File.expand_path(f)
63
+ local_dir = File.dirname(f)
64
+ f = local_dir + "/**/" + File.basename(f) if recursive
65
+
66
+ Dir.glob(f, all==true ? File::FNM_DOTMATCH : 0) do |f2|
67
+ if(!File.directory? f2)
68
+ remote_dir = dir
69
+ append_dir = File.dirname(f2).sub(/^#{local_dir}\/*/,"")
70
+ remote_dir = remote_dir + "/" + append_dir if append_dir != ""
71
+ if File.exists?(f2)
72
+ puts "Storing file #{f2} in remote dir \"#{remote_dir}\""
73
+ i.store_file(f2,remote_dir,subject)
74
+ else
75
+ puts "File #{f2} does not exist."
76
+ end
77
+ end
78
+ end
79
+ end
80
+ when 'get':
81
+ files.each do |f|
82
+ f = /.+/ if f == '*'
83
+ puts "Getting files"
84
+ i.get_file(dir, Regexp.new(f), recursive, all).each do |a|
85
+ puts a
86
+ end
87
+ end
88
+ when 'rm':
89
+ files.each do |f|
90
+ f = /.+/ if f == '*'
91
+ puts "Deleting files"
92
+ i.rm_file(dir, Regexp.new(f), recursive, all).each do |a|
93
+ puts a
94
+ end
95
+ end
96
+ when 'mkdir':
97
+ i.mkdir(dir)
98
+ when 'rmdir':
99
+ i.rmdir(dir, recursive, all)
100
+ when 'quota':
101
+ q = i.quota("INBOX")
102
+ puts "Used #{q[1]['usage'].to_s} of #{q[1]['quota'].to_s}"
103
+ when 'snipplet':
104
+
105
+ i.snipplet(subject,text,dir, nil)
106
+ else
107
+ raise "unimplemented command #{command}"
108
+ end
109
+
110
+
111
+
112
+ i.disconnect
113
+ else
114
+ puts "command #{command} is unimplemented"
115
+ end
116
+
117
+ rescue
118
+ puts "An error has occured #{$!}"
119
+ end
@@ -0,0 +1,351 @@
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
+ default:
16
+ email: account@gmail.com
17
+ password: password
18
+ store_tag: IMAPSTORE
19
+ imap_server: imap.gmail.com
20
+ imap_port: 993
21
+ ssl: true
22
+
23
+ other:
24
+ email: other_account@gmail.com
25
+ password: password
26
+ store_tag: IMAPSTORE
27
+ imap_server: imap.gmail.com
28
+ imap_port: 993
29
+ ssl: true
30
+ END
31
+
32
+ def self.create_config_file(file = File.expand_path('~/.imapstore/config.yml'))
33
+ if !File.exists?(file)
34
+ puts "creating #{File.dirname(file)}"
35
+ FileUtils.mkdir_p(File.dirname(file))
36
+ File.open(file,"w").write(CONFIG_TEMPLATE)
37
+ end
38
+ end
39
+
40
+ def initialize(file = File.expand_path('~/.imapstore/config.yml'), imapstore="default")
41
+ puts "Initializing IMAP" if @verbose
42
+ @versioned = true
43
+ @verbose = false
44
+
45
+ puts "Getting configuration file #{file} for account #{imapstore}" if @verbose
46
+ get_config(file, imapstore)
47
+ connect
48
+ end
49
+
50
+ def versioned
51
+ @versioned
52
+ end
53
+
54
+ def versioned=(is_versioned)
55
+ @versioned = is_versioned
56
+ end
57
+
58
+ def email
59
+ @email
60
+ end
61
+
62
+ def password
63
+ @password
64
+ end
65
+
66
+ def store_tag
67
+ @store_tag
68
+ end
69
+
70
+ def imap_server
71
+ @imap_server
72
+ end
73
+
74
+ def imap_port
75
+ @imap_port
76
+ end
77
+
78
+ def verbose
79
+ @verbose
80
+ end
81
+
82
+ def verbose=(value)
83
+ @verbose = value
84
+ end
85
+
86
+ def connect()
87
+ if !@imap && @email && @password && @imap_server && @imap_port
88
+ if(@ssl == true)
89
+ @imap = Net::IMAP.new(@imap_server, @imap_port, true)
90
+ else
91
+ @imap = Net::IMAP.new(@imap_server, @imap_port, false)
92
+ end
93
+ @imap.login(@email, @password)
94
+ end
95
+ end
96
+
97
+ def disconnect()
98
+ if @imap
99
+ @imap.logout()
100
+ begin
101
+ @imap.disconnect()
102
+ rescue
103
+ end
104
+ end
105
+ end
106
+
107
+ def get_config(file = File.expand_path('~/.imapstore/config.yml'), imapstore = "default")
108
+ if !File.exists?(file)
109
+ File.open(file,"w").write(CONFIG_TEMPLATE)
110
+ end
111
+
112
+ aConfig = YAML::load_file(file)
113
+
114
+ #COFIGURATION SECTION
115
+ @email = aConfig[imapstore]['email']
116
+ @password = aConfig[imapstore]['password']
117
+ @store_tag = aConfig[imapstore]['store_tag'] || "IMAPSTORE"
118
+ @imap_server = aConfig[imapstore]['imap_server']
119
+ @imap_port = aConfig[imapstore]['imap_port']
120
+ @ssl = aConfig[imapstore]['ssl'] || false
121
+ #END CONFIGURATION SECTION
122
+
123
+ aConfig
124
+ end
125
+
126
+ def snipplet(subject = "snipplet", body = "", folder="snipplets", file = nil)
127
+ puts "Storing snipplet" if @verbose
128
+
129
+ mail = TMail::Mail.new
130
+ mail.to = @email
131
+ mail.from = @email
132
+ mail.subject = subject
133
+
134
+ mail.date = Time.now
135
+ mail.mime_version = '1.0'
136
+
137
+ mailpart1=TMail::Mail.new
138
+ mailpart1.set_content_type 'text', 'plain'
139
+ mailpart1.body = body
140
+ mail.parts << mailpart1
141
+ mail.set_content_type 'multipart', 'mixed'
142
+
143
+ # if file && FileTest.exists?(file)
144
+ # mailpart=TMail::Mail.new
145
+ # mailpart.body = Base64.encode64(chunk.to_s)
146
+ # mailpart.transfer_encoding="Base64"
147
+ # mailpart['Content-Disposition'] = "attachment; filename=#{CGI::escape(basename)}"
148
+ # mail.parts.push(mailpart)
149
+ # end
150
+ @imap.create(folder) if !@imap.list("", folder)
151
+ @imap.append(folder, mail.to_s, [:Seen], Time.now)
152
+
153
+ end
154
+
155
+ def store_file_chunk( file, folder = "INBOX", subject = "", chunk=nil, chunk_no=0, max_chunk_no=0 )
156
+ if(max_chunk_no>0)
157
+ puts "Storing part #{chunk_no} of #{max_chunk_no}"
158
+ end
159
+ basename = File.basename(file)
160
+ version = 0
161
+
162
+ if max_chunk_no == 0
163
+ tag = "#{@store_tag}[#{basename}]"
164
+ else
165
+ tag = "#{@store_tag}[#{basename}](#{chunk_no}-#{max_chunk_no})"
166
+ end
167
+ @imap.select(folder)
168
+ @imap.search(["SUBJECT", tag, "NOT", "DELETED"]).each do |message_id|
169
+ if @versioned==true
170
+ version = version + 1
171
+ else
172
+ @imap.store(message_id, "+FLAGS", [:Deleted])
173
+ end
174
+ end
175
+ @imap.expunge
176
+
177
+ mail = TMail::Mail.new
178
+ mail.to = @email
179
+ mail.from = @email
180
+ if max_chunk_no == 0
181
+ mail.subject = "#{@store_tag}[#{basename}]"
182
+ else
183
+ mail.subject = "#{@store_tag}[#{basename}](#{chunk_no}-#{max_chunk_no})"
184
+ end
185
+
186
+ if version > 0
187
+ mail.subject = mail.subject + "(v. #{version})"
188
+ end
189
+
190
+ if subject
191
+ mail.subject = mail.subject + ": #{subject}"
192
+ end
193
+
194
+ mail.date = Time.now
195
+ mail.mime_version = '1.0'
196
+
197
+ mailpart1=TMail::Mail.new
198
+ mailpart1.set_content_type 'text', 'plain'
199
+ mailpart1.body = "This is a mail storage message of file #{file}"
200
+ mail.parts << mailpart1
201
+ mail.set_content_type 'multipart', 'mixed'
202
+
203
+ if FileTest.exists?(file)
204
+ mailpart=TMail::Mail.new
205
+ mailpart.body = Base64.encode64(chunk.to_s)
206
+ mailpart.transfer_encoding="Base64"
207
+ if max_chunk_no == 0
208
+ mailpart['Content-Disposition'] = "attachment; filename=#{CGI::escape(basename)}"
209
+ else
210
+ mailpart['Content-Disposition'] = "attachment; filename=#{CGI::escape(basename)}_#{chunk_no}-#{max_chunk_no}"
211
+ end
212
+ mail.parts.push(mailpart)
213
+ end
214
+
215
+
216
+ @imap.append(folder, mail.to_s, [:Seen], File.new(file).atime)
217
+
218
+ end
219
+
220
+ def store_file( file, folder = "INBOX", subject = "")
221
+
222
+ @imap.create(folder) if !@imap.list("", folder)
223
+
224
+ size = File.size(file)
225
+ if(size > MAX_FILE_SIZE)
226
+ remaining = size
227
+ max_chunk_no = (size/CHUNK_SIZE)+1
228
+ chunk_no = 1
229
+ File.open(file) do |f|
230
+ while(remaining>0)
231
+ content = f.read(CHUNK_SIZE)
232
+ store_file_chunk( file, folder, subject, content, chunk_no, max_chunk_no)
233
+ chunk_no = chunk_no +1
234
+ remaining = remaining - CHUNK_SIZE
235
+ end
236
+ end
237
+ else
238
+ content=File.open(file).read
239
+ store_file_chunk( file, folder, subject, content)
240
+ end
241
+ end
242
+
243
+ def transverse(target_folder = "INBOX", glob = /.+/, recursive = false, dot_files = false, folder_only=false)
244
+ file_list=[]
245
+
246
+
247
+
248
+
249
+ begin
250
+ target_folder = "" if target_folder == "/"
251
+
252
+ puts "..... fetching #{target_folder} " if @verbose
253
+
254
+ @imap.list(target_folder, "*").each do |folder|
255
+
256
+ puts "..... transversing #{folder.name} " if @verbose
257
+
258
+ if ((recursive == true) && (target_folder == "" ? true : folder.name.match(/^#{target_folder}(\/.+)*$/))) || (folder.name == target_folder)
259
+ puts "..... got hit transversing #{folder.name} " if @verbose
260
+ file_list << folder.name
261
+ yield(folder.name, nil, nil, nil, nil) if block_given?
262
+
263
+ if((!folder.attr.include? :Noselect) && (folder_only==false))
264
+
265
+ @imap.select(folder.name)
266
+
267
+ @imap.search(["NOT", "DELETED"]).each do |message_id|
268
+ a = @imap.fetch(message_id, "RFC822")
269
+ mail = TMail::Mail.parse(a[0].attr["RFC822"])
270
+ file_name = mail.subject.match(/^[^\[]+\[([^\]]+)\]/)[1]
271
+ file_list << folder.name + "/" + file_name if file_name.match(glob)
272
+ yield(folder.name, file_name, message_id, mail, file_name) if block_given? && file_name.match(glob)
273
+ end
274
+ end
275
+ end
276
+ end
277
+ rescue
278
+ end
279
+
280
+ file_list.sort
281
+ end
282
+
283
+ def ls(target_folder = "INBOX", glob = /.+/, recursive = false, dot_files = false)
284
+ transverse(target_folder, glob, recursive, dot_files, false)
285
+ end
286
+
287
+ def get_file(target_folder = "INBOX", glob = /.+/, recursive = false, dot_files = false)
288
+ file_list = transverse(target_folder, glob, recursive, dot_files, false) do |folder, file, message_id, mail, file_name|
289
+
290
+ if mail && mail.multipart? then
291
+ mail.parts.each do |m|
292
+ if !m.main_type
293
+ append_dir = folder.sub(/^#{target_folder}\/*/,"")
294
+ if append_dir != ""
295
+ Dir.mkdir(append_dir) if !File.exists? append_dir
296
+
297
+ file_name = append_dir + "/" + file_name
298
+ end
299
+ File.open(file_name,"w").write(m.body)
300
+ end
301
+ end
302
+ end
303
+ end
304
+ end
305
+
306
+
307
+
308
+ def rm_file(target_folder = "INBOX", glob = /.+/, recursive = false, dot_files = false)
309
+ file_list = transverse(target_folder, glob, false, dot_files, false) do |folder, file, message_id, mail, file_name|
310
+ if file && message_id
311
+ @imap.store(message_id, "+FLAGS", [:Deleted])
312
+ @imap.expunge
313
+ end
314
+ end
315
+
316
+ file_list
317
+ end
318
+
319
+ def mkdir(folder)
320
+ @imap.create(folder)
321
+ end
322
+
323
+ def rmdir(target_folder, recursive = false, dot_files = false)
324
+ folders = []
325
+ puts "..... Deleting #{target_folder}" if @verbose
326
+
327
+ transverse(target_folder, /.+/, recursive, dot_files, false) do |folder, file, message_id, mail, file_name|
328
+ puts "..... assigning dir #{folder} for removal" if @verbose
329
+ folders << folder if !(folders.include? folder)
330
+
331
+ if file && message_id
332
+ puts "..... actually removing dir #{folder} file #{file_name}" if @verbose
333
+ @imap.store(message_id, "+FLAGS", [:Deleted])
334
+ @imap.expunge
335
+ end
336
+ end
337
+
338
+
339
+ folders.each do |folder|
340
+ puts "..... actually removing dir #{folder}" if @verbose
341
+ @imap.delete(folder)
342
+ end
343
+
344
+ folders
345
+ end
346
+
347
+ def quota(folder)
348
+ @imap.getquotaroot(folder)
349
+ end
350
+ end
351
+ end
data/lib/imapstore.rb ADDED
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'imapstore/imapstore.rb'
5
+
6
+ module IMAPSTORE
7
+ VERSION = '0.4.4'
8
+
9
+ 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
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'imapstore'
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,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imapstore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
+ platform: ruby
6
+ authors:
7
+ - Joan Marc Carbo Arnau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-11 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rdoc
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.2.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: tmail
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: getoptions
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0.1"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: newgem
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.3
54
+ version:
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ type: :development
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 1.8.0
64
+ version:
65
+ description: ruby gem to use an imap server as a file storage device
66
+ email:
67
+ - jmcarbo@gmail.com
68
+ executables:
69
+ - imapstore
70
+ extensions: []
71
+
72
+ extra_rdoc_files:
73
+ - History.txt
74
+ - Manifest.txt
75
+ - PostInstall.txt
76
+ - README.rdoc
77
+ files:
78
+ - History.txt
79
+ - Manifest.txt
80
+ - PostInstall.txt
81
+ - README.rdoc
82
+ - Rakefile
83
+ - bin/imapstore
84
+ - lib/imapstore.rb
85
+ - lib/imapstore/imapstore.rb
86
+ - script/console
87
+ - script/destroy
88
+ - script/generate
89
+ - spec/imapstore_spec.rb
90
+ - spec/spec.opts
91
+ - spec/spec_helper.rb
92
+ - tasks/rspec.rake
93
+ has_rdoc: true
94
+ homepage: http://wiki.github.com/jmcarbo/imapstore
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --main
98
+ - README.rdoc
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ version:
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ version:
113
+ requirements: []
114
+
115
+ rubyforge_project: imapstore
116
+ rubygems_version: 1.3.1
117
+ signing_key:
118
+ specification_version: 2
119
+ summary: ruby gem to use an imap server as a file storage device
120
+ test_files: []
121
+