gmail-to-dropbox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,17 @@
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 "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.2.0"
12
+ gem "jeweler", "~> 1.8.4"
13
+ gem "ruby-gmail", ">= 0.3.0"
14
+ gem "dropbox-sdk", ">= 1.5.1"
15
+ #gem "etc"
16
+ #gem "rcov", ">= 0"
17
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 RONGHAI
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.
@@ -0,0 +1,19 @@
1
+ = gmail-to-dropbox
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to gmail-to-dropbox
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2013 RONGHAI. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require 'rake'
6
+
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
10
+ gem.name = "gmail-to-dropbox"
11
+ gem.homepage = "http://github.com/RONGHAI/gmail-to-dropbox"
12
+ gem.license = "MIT"
13
+ gem.summary = %Q{sync gmail/Dropbox unread emails' attachements to dropbox}
14
+ gem.description = %Q{sync all attachments of gmail/Dropbox unread emails to dropbox}
15
+ gem.email = "ronghai.wei@msn.com"
16
+ gem.authors = ["RONGHAI"]
17
+ gem.post_install_message = ""
18
+ end
19
+ Jeweler::RubygemsDotOrgTasks.new
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ #require 'rcov/rcovtask'
29
+ #Rcov::RcovTask.new do |test|
30
+ # test.libs << 'test'
31
+ # test.pattern = 'test/**/test_*.rb'
32
+ # test.verbose = true
33
+ # test.rcov_opts << '--exclude "gems/*"'
34
+ #end
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "l5m-tools #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gmail'
3
+ require "fileutils"
4
+ require 'dropbox_sdk'
5
+ module Gmail2Dropbox
6
+ class Gmail2Dropbox
7
+ ##
8
+ # = Args
9
+ # * options = {}
10
+ # = Example
11
+ # gmail_to_dropbox = Gmail2Dropbox.new({username:"gmail@gmail.com", password:"pzzwd", access_type:"dropbox", app_key:"hkm3y941q9gq", app_secret:"5lyw9dnfyx"})
12
+ def initialize(options={})
13
+ class << self
14
+ class << self
15
+ attr_accessor :username, :password, :access_type, :app_key, :app_secret
16
+ end
17
+ end
18
+ meta.username = options[:username]
19
+ meta.password = options[:password]
20
+ meta.access_type = options[:access_type].to_sym
21
+ meta.app_key = options[:app_key]
22
+ meta.app_secret = options[:app_secret]
23
+ @gmail = Gmail.new(meta.username, meta.password)
24
+ @dropbox_client = DropboxClient.new(dropbox_session, meta.access_type)
25
+ end
26
+
27
+
28
+
29
+ ##
30
+ # sync attacments of unread mails with label "Dropbox" to dropbox root folder.
31
+ # = Args
32
+ # * mark_read, mark email to read
33
+ # * :yields: gmail and return emails. if there is no block, it will use unread mails in "Dropbox"
34
+ # = Return
35
+ # all unread mails
36
+ # = Example
37
+ # gmail_to_dropbox.sync(false)
38
+ def sync mark_read = true
39
+ @gmail.login unless @gmail.logged_in?
40
+ if block_given?
41
+ emails = yeild @gmail
42
+ else
43
+ emails = @gmail.mailbox("Dropbox").emails(:unread)
44
+ emails.reject!{|mail| mail.attachments == nil }
45
+ end
46
+ emails.each{|email|
47
+ email.attachments.each do |attachment|
48
+ @dropbox_client.put_file('/'+attachment.filename, attachment.body.decoded )
49
+ end
50
+ email.mark(:read) if mark_read
51
+ }
52
+ end
53
+
54
+ def disconnect
55
+ @gmail.disconnect
56
+ end
57
+
58
+ private
59
+ def meta
60
+ class << self; self end
61
+ end
62
+ def dropbox_session
63
+ return @session unless @session.nil?
64
+ serial_folder = File.expand_path('~/.dropbox')
65
+ FileUtils.mkdir_p serial_folder
66
+ begin
67
+ file = "#{serial_folder}/.dropbox.serial"
68
+ serial = File.open(file, "rb").read
69
+ @session = DropboxSession.deserialize(serial)
70
+ rescue
71
+ end
72
+ unless @session
73
+ while true
74
+ begin
75
+ @session = DropboxSession.new(meta.app_key, meta.app_secret)
76
+ puts "Please visit that website and hit 'Allow', then hit Enter here. \n #{@session.get_authorize_url}"; gets
77
+ File.open(file, 'w') { |file| file.write(@session.serial) }
78
+ break
79
+ rescue
80
+ next
81
+ end
82
+ end
83
+ end
84
+ @session
85
+ end
86
+ end
87
+ end
88
+
89
+ __END__
90
+
@@ -0,0 +1,18 @@
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 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'gmail-to-dropbox'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestGmailToDropbox < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gmail-to-dropbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - RONGHAI
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: &70150666641260 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70150666641260
25
+ - !ruby/object:Gem::Dependency
26
+ name: rdoc
27
+ requirement: &70150666640400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.12'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70150666640400
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70150666638780 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70150666638780
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70150666637940 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70150666637940
58
+ - !ruby/object:Gem::Dependency
59
+ name: ruby-gmail
60
+ requirement: &70150666636580 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 0.3.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70150666636580
69
+ - !ruby/object:Gem::Dependency
70
+ name: dropbox-sdk
71
+ requirement: &70150666651960 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 1.5.1
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70150666651960
80
+ description: sync all attachments of gmail/Dropbox unread emails to dropbox
81
+ email: ronghai.wei@msn.com
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.rdoc
87
+ files:
88
+ - .document
89
+ - Gemfile
90
+ - LICENSE.txt
91
+ - README.rdoc
92
+ - Rakefile
93
+ - VERSION
94
+ - lib/gmail-to-dropbox.rb
95
+ - test/helper.rb
96
+ - test/test_gmail-to-dropbox.rb
97
+ homepage: http://github.com/RONGHAI/gmail-to-dropbox
98
+ licenses:
99
+ - MIT
100
+ post_install_message: ''
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.17
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: sync gmail/Dropbox unread emails' attachements to dropbox
122
+ test_files: []