anotherinbox 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,9 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
+ gem "aws-s3"
7
+ gem "gmail"
8
+
6
9
  # Add dependencies to develop your gem here.
7
10
  # Include everything needed to run rake, tests, features, etc.
8
11
  group :development do
@@ -10,4 +13,6 @@ group :development do
10
13
  gem "bundler", "~> 1.0.0"
11
14
  gem "jeweler", "~> 1.5.2"
12
15
  gem "rcov", ">= 0"
16
+ gem "ruby-debug"
17
+ gem "pry"
13
18
  end
@@ -0,0 +1,69 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ aws-s3 (0.6.2)
5
+ builder
6
+ mime-types
7
+ xml-simple
8
+ builder (3.0.0)
9
+ coderay (0.9.8)
10
+ columnize (0.3.5)
11
+ git (1.2.5)
12
+ gmail (0.4.0)
13
+ gmail_xoauth (>= 0.3.0)
14
+ mail (>= 2.2.1)
15
+ mime (>= 0.1)
16
+ gmail_xoauth (0.3.0)
17
+ oauth (>= 0.3.6)
18
+ i18n (0.6.0)
19
+ jeweler (1.5.2)
20
+ bundler (~> 1.0.0)
21
+ git (>= 1.2.5)
22
+ rake
23
+ linecache (0.46)
24
+ rbx-require-relative (> 0.0.4)
25
+ mail (2.3.0)
26
+ i18n (>= 0.4.0)
27
+ mime-types (~> 1.16)
28
+ treetop (~> 1.4.8)
29
+ method_source (0.6.7)
30
+ ruby_parser (>= 2.3.1)
31
+ mime (0.1)
32
+ mime-types (1.17.2)
33
+ oauth (0.4.5)
34
+ polyglot (0.3.3)
35
+ pry (0.9.7.4)
36
+ coderay (~> 0.9.8)
37
+ method_source (~> 0.6.7)
38
+ ruby_parser (>= 2.3.1)
39
+ slop (~> 2.1.0)
40
+ rake (0.9.2.2)
41
+ rbx-require-relative (0.0.5)
42
+ rcov (0.9.11)
43
+ ruby-debug (0.10.4)
44
+ columnize (>= 0.1)
45
+ ruby-debug-base (~> 0.10.4.0)
46
+ ruby-debug-base (0.10.4)
47
+ linecache (>= 0.3)
48
+ ruby_parser (2.3.1)
49
+ sexp_processor (~> 3.0)
50
+ sexp_processor (3.0.9)
51
+ shoulda (2.11.3)
52
+ slop (2.1.0)
53
+ treetop (1.4.10)
54
+ polyglot
55
+ polyglot (>= 0.3.1)
56
+ xml-simple (1.1.1)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ aws-s3
63
+ bundler (~> 1.0.0)
64
+ gmail
65
+ jeweler (~> 1.5.2)
66
+ pry
67
+ rcov
68
+ ruby-debug
69
+ shoulda
@@ -2,13 +2,14 @@
2
2
 
3
3
  By Rodrigo Franco
4
4
 
5
- The original {Otherinbox Defender}[http://mashable.com/2008/09/08/otherinbox/] is no more. Sadly, the newest version is subpar and do not meet my needs. This project attempts to reproduce the core functionalities of OIB Defender using a GMail account. As of right now, the following functionalities are implemented:
5
+ The original {Otherinbox Defender}[http://mashable.com/2008/09/08/otherinbox/] is no more. Sadly, the current version is subpar and do not meet my needs. This project attempts to reproduce the core functionalities of OIB Defender using a GMail account. As of right now, the following functionalities are implemented:
6
6
 
7
7
  * Emails are automatically labeled by mailbox name
8
8
  * First email sent to a new mailbox is forwarded to your personal email address
9
- * Daily digest sent to your personal email address, with the list of emails received by day
9
+ * Daily digest sent to your personal email address, with the list of emails received the day before
10
+ * Emails previews can be generated, so you can easily see yesterday messages without login into your anotherinbox mailbox. (Optional)
10
11
 
11
- == Getting starteds (Pre-requisites)
12
+ == Getting started (Pre-requisites)
12
13
 
13
14
  * {Create a new google apps account}[http://www.google.com/apps/intl/en/business/index.html] (using a new domain is highly recommended)
14
15
  * Setup one email account on it
@@ -24,19 +25,30 @@ The original {Otherinbox Defender}[http://mashable.com/2008/09/08/otherinbox/] i
24
25
 
25
26
  * Create a .anotherinbox file in your home directory. It should look like this:
26
27
 
28
+ accounts:
29
+ - username: anotherinbox@gmail.com
30
+ password: password42
31
+ email: personal@email.com
27
32
 
28
- anotherinbox:
29
- username: anotherinbox@gmail.com
30
- password: password42
31
- personal:
32
- email: personal@email.com
33
+ - username: anotheranotherinbox@gmail.com
34
+ password: password42!
35
+ email: personal2@email.com
36
+
37
+ config:
38
+ use_preview: false
39
+ bucket: anotherinbox.amazon.bucket
40
+ aws_key: KEY-GOES-HERE
41
+ aws_secret: SECRET-GOES-HERE
42
+
43
+ * Just one account is required, but you can have more than one if you want.
44
+ * To enable the digest previews, change use_preview to true and enter your AWS credentials (and bucket name).
33
45
 
34
46
  * Add the following lines to your cron tab:
35
47
 
36
48
  */5 * * * * anotherinbox process
37
49
  55 04 * * * anotherinbox digest
38
50
 
39
- That will ensure the script organize your mailbox each 5 minutes. It will also send you the daily digest at 04:55am.
51
+ That will ensure the script organizes your mailbox each 5 minutes. It will also send you the daily digest at 04:55am.
40
52
 
41
53
  == Contributing to anotherinbox
42
54
 
@@ -50,6 +62,5 @@ That will ensure the script organize your mailbox each 5 minutes. It will also s
50
62
 
51
63
  == Copyright
52
64
 
53
- Copyright (c) 2011 rodrigo franco (caffo). See LICENSE.txt for
54
- further details.
65
+ Copyright (c) 2011 rodrigo franco (caffo). See LICENSE.txt for further details.
55
66
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{anotherinbox}
8
- s.version = "0.3.7"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["rodrigo franco (caffo)"]
12
- s.date = %q{2011-01-25}
12
+ s.date = %q{2011-12-14}
13
13
  s.default_executable = %q{anotherinbox}
14
14
  s.description = %q{The original Otherinbox Defender is no more. Sadly, the newest version is subpar and do not meet my needs. This project attempts to reproduce the core functionalities of OIB Defender using a GMail account.}
15
15
  s.email = %q{caffeine@gmail.com}
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
19
19
  "README.rdoc"
20
20
  ]
21
21
  s.files = [
22
- ".document",
23
22
  "Gemfile",
23
+ "Gemfile.lock",
24
24
  "LICENSE.txt",
25
25
  "README.rdoc",
26
26
  "Rakefile",
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.homepage = %q{http://github.com/caffo/anotherinbox}
35
35
  s.licenses = ["MIT"]
36
36
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.7}
37
+ s.rubygems_version = %q{1.5.3}
38
38
  s.summary = %q{gmail based otherinbox defender alternative}
39
39
  s.test_files = [
40
40
  "test/helper.rb",
@@ -42,27 +42,38 @@ Gem::Specification.new do |s|
42
42
  ]
43
43
 
44
44
  if s.respond_to? :specification_version then
45
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
45
  s.specification_version = 3
47
46
 
48
47
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<aws-s3>, [">= 0"])
49
+ s.add_runtime_dependency(%q<gmail>, [">= 0"])
49
50
  s.add_development_dependency(%q<shoulda>, [">= 0"])
50
51
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
52
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
52
53
  s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ s.add_development_dependency(%q<ruby-debug>, [">= 0"])
55
+ s.add_development_dependency(%q<pry>, [">= 0"])
53
56
  s.add_runtime_dependency(%q<gmail>, [">= 0.4.0"])
54
57
  else
58
+ s.add_dependency(%q<aws-s3>, [">= 0"])
59
+ s.add_dependency(%q<gmail>, [">= 0"])
55
60
  s.add_dependency(%q<shoulda>, [">= 0"])
56
61
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
62
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
58
63
  s.add_dependency(%q<rcov>, [">= 0"])
64
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
65
+ s.add_dependency(%q<pry>, [">= 0"])
59
66
  s.add_dependency(%q<gmail>, [">= 0.4.0"])
60
67
  end
61
68
  else
69
+ s.add_dependency(%q<aws-s3>, [">= 0"])
70
+ s.add_dependency(%q<gmail>, [">= 0"])
62
71
  s.add_dependency(%q<shoulda>, [">= 0"])
63
72
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
73
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
74
  s.add_dependency(%q<rcov>, [">= 0"])
75
+ s.add_dependency(%q<ruby-debug>, [">= 0"])
76
+ s.add_dependency(%q<pry>, [">= 0"])
66
77
  s.add_dependency(%q<gmail>, [">= 0.4.0"])
67
78
  end
68
79
  end
@@ -9,22 +9,17 @@ if ARGV[0]
9
9
  settings = YAML::load(File.open("#{ENV['HOME']}/.anotherinbox"))
10
10
  case ARGV[0]
11
11
  when "process"
12
- Anotherinbox.process_inbox!(settings["anotherinbox"]["username"],
13
- settings["anotherinbox"]["password"],
14
- settings["personal"]["email"])
15
- if settings["anotheranotherinbox"].present?
16
- Anotherinbox.process_inbox!(settings["anotheranotherinbox"]["username"],
17
- settings["anotheranotherinbox"]["password"],
18
- settings["personal"]["email"])
12
+ settings["accounts"].each do |s|
13
+ Anotherinbox.process_inbox!(s["username"],
14
+ s["password"],
15
+ s["email"])
19
16
  end
20
17
  when "digest"
21
- Anotherinbox.daily_digest(settings["anotherinbox"]["username"],
22
- settings["anotherinbox"]["password"],
23
- settings["personal"]["email"])
24
- if settings["anotheranotherinbox"].present?
25
- Anotherinbox.daily_digest(settings["anotheranotherinbox"]["username"],
26
- settings["anotheranotherinbox"]["password"],
27
- settings["personal"]["email"])
18
+ settings["accounts"].each do |s|
19
+ Anotherinbox.daily_digest(s["username"],
20
+ s["password"],
21
+ s["email"],
22
+ settings["config"])
28
23
  end
29
24
  end
30
25
  else
@@ -1,7 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'gmail'
3
3
  require 'logger'
4
- require "date"
4
+ require 'date'
5
+ require 'digest/sha1'
6
+ require 'aws/s3'
5
7
 
6
8
  class Anotherinbox < Object
7
9
  def self.process_inbox!(email_address, password, target_email)
@@ -34,41 +36,96 @@ class Anotherinbox < Object
34
36
  log.info("Process finished")
35
37
  end
36
38
 
37
- def self.daily_digest(email_address, password, target_email)
38
- def self.email_template(new_messages, account)
39
+ def self.daily_digest(email_address, password, target_email, configs)
40
+
41
+ def self.email_template(new_messages, account, configs, email_address)
39
42
  # we all know, inline styles sucks. sadly, it's the
40
43
  # only way to get them into gmail.
41
44
  response = ""
42
- response += "<h1 style='margin-left: 40px; color: #000000;'>Daily Digest for #{Date.yesterday}</h1>"
43
- response += "<h3 style='color: #aaaaaa; margin-left: 40px; margin-top: -20px; margin-bottom: 30px;'>for #{account}</h3>"
45
+ response += "<h1 style='margin-left: 40px; color: #000000;'>Daily Digest for #{(Date.today - 1)}</h1>"
46
+ response += "<h3 style='color: #aaaaaa; margin-left: 40px; margin-top: -10px; margin-bottom: 30px;'>for #{account}</h3>"
44
47
  response += "<ul style='width: 90%;'>"
45
- new_messages.sort.each {|m| response += "<li style='margin-bottom: 10px; list-style: none; color: #3485ae; border-bottom: 1px dotted #ccc; padding-bottom: 10px; font-weight: bold;'>#{m[0]}: <strong style='color: #000000; font-weight: normal;'>#{m[1]}</strong> </li>"}
48
+
49
+ new_messages.sort_by{|x| x[0]}.each do |m|
50
+ response += "<li style='margin-bottom: 10px; list-style: none; color: #3485ae; border-bottom: 1px dotted #ccc; padding-bottom: 10px; font-weight: bold;'>"
51
+ response += m[0]
52
+ response += ": <strong style='color: #000000; font-weight: normal;'>"
53
+
54
+ if configs["use_preview"]
55
+ response += "<a href='http://"
56
+ response += configs["bucket"]
57
+ response += ".s3.amazonaws.com/"
58
+ response += email_address.gsub("@", "_").gsub(".", "_")
59
+ response += "_"
60
+ response += Digest::SHA1.hexdigest(m[1])
61
+ response += ".html'>#{m[1]}</a>"
62
+ else
63
+ response += m[1]
64
+ end
65
+
66
+ response += "</strong> </li>"
67
+ end
68
+
46
69
  response += "</ul>"
47
70
  return response
48
71
  end
49
72
 
73
+ def self.generate_previews(new_messages, configs, email_address)
74
+ AWS::S3::Base.establish_connection!(
75
+ :access_key_id => configs["aws_key"],
76
+ :secret_access_key => configs["aws_secret"]
77
+ )
78
+
79
+ # set file prefix. useful when we have more than one
80
+ # anotherinbox account running in the same script instance
81
+ prefix = email_address.gsub("@", "_").gsub(".", "_")
82
+
83
+ #binding.pry
84
+
85
+ # cleanup the bucket
86
+ while (AWS::S3::Bucket.objects(configs["bucket"], :prefix => prefix).size > 0) do
87
+ AWS::S3::Bucket.objects(configs["bucket"]).each do |file|
88
+ file.delete if file.key.match(prefix)
89
+ end
90
+ end
91
+
92
+ new_messages.sort_by{|x| x[0]}.each do |m|
93
+ filename = Digest::SHA1.hexdigest(m[1])
94
+ AWS::S3::S3Object.store("#{prefix}_#{filename}.html", m[2].to_s, configs["bucket"], :access => :public_read)
95
+ end
96
+ end
97
+
98
+
50
99
  log = Logger.new(STDOUT)
51
100
  emails = []
52
101
  aib_domain = email_address.split("@")[1]
53
102
 
103
+ log.info("Account: #{email_address}")
104
+
54
105
  Gmail.new(email_address, password) do |gmail|
55
- gmail.mailbox('[Gmail]/All Mail').emails(:on => Date.yesterday).each do |email|
106
+ gmail.mailbox('[Gmail]/All Mail').emails(:on => (Date.today - 1)).each do |email|
56
107
  next if email.subject.match("Daily Digest for") rescue nil
57
108
  next if "#{email.from[0]['mailbox']}@#{email.from[0]['host']}" == email_address
58
109
  mailbox = email[:to][0].mailbox.downcase rescue "unknown"
59
- emails << [mailbox, email.subject]
110
+ body = email.html_part.nil? ? email.body : email.html_part.body
111
+ emails << [mailbox, email.subject, body]
60
112
  end
61
113
 
62
114
  if emails.size > 0
63
- log.info("Sending daily digest with #{emails.size} entries..")
64
- digest = gmail.message
65
- digest.to = target_email
66
- digest.subject = "[#{aib_domain}] Daily Digest for #{Date.yesterday}"
67
- digest.content_type = "text/html"
68
- digest.body = self.email_template(emails, aib_domain)
69
- digest.deliver!
70
- end
115
+ if configs["use_preview"]
116
+ log.info("Generating previews...")
117
+ self.generate_previews(emails, configs, email_address)
118
+ end
119
+
120
+ log.info("Sending daily digest with #{emails.size} entries..")
121
+ digest = gmail.message
122
+ digest.to = target_email
123
+ digest.subject = "[#{aib_domain}] Daily Digest for #{(Date.today - 1)}"
124
+ digest.content_type = "text/html"
125
+ digest.body = self.email_template(emails, aib_domain, configs, email_address)
126
+ digest.deliver!
127
+ end
71
128
  end
72
129
  log.info("Process finished")
73
130
  end
74
- end
131
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anotherinbox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 7
10
- version: 0.3.7
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - rodrigo franco (caffo)
@@ -15,14 +15,26 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-25 00:00:00 -02:00
18
+ date: 2011-12-14 00:00:00 -05:00
19
19
  default_executable: anotherinbox
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- type: :development
22
+ type: :runtime
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ name: aws-s3
33
+ version_requirements: *id001
23
34
  prerelease: false
24
- name: shoulda
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ requirement: &id002 !ruby/object:Gem::Requirement
26
38
  none: false
27
39
  requirements:
28
40
  - - ">="
@@ -31,12 +43,26 @@ dependencies:
31
43
  segments:
32
44
  - 0
33
45
  version: "0"
34
- requirement: *id001
46
+ name: gmail
47
+ version_requirements: *id002
48
+ prerelease: false
35
49
  - !ruby/object:Gem::Dependency
36
50
  type: :development
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ name: shoulda
61
+ version_requirements: *id003
37
62
  prerelease: false
38
- name: bundler
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
63
+ - !ruby/object:Gem::Dependency
64
+ type: :development
65
+ requirement: &id004 !ruby/object:Gem::Requirement
40
66
  none: false
41
67
  requirements:
42
68
  - - ~>
@@ -47,12 +73,12 @@ dependencies:
47
73
  - 0
48
74
  - 0
49
75
  version: 1.0.0
50
- requirement: *id002
76
+ name: bundler
77
+ version_requirements: *id004
78
+ prerelease: false
51
79
  - !ruby/object:Gem::Dependency
52
80
  type: :development
53
- prerelease: false
54
- name: jeweler
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
81
+ requirement: &id005 !ruby/object:Gem::Requirement
56
82
  none: false
57
83
  requirements:
58
84
  - - ~>
@@ -63,12 +89,26 @@ dependencies:
63
89
  - 5
64
90
  - 2
65
91
  version: 1.5.2
66
- requirement: *id003
92
+ name: jeweler
93
+ version_requirements: *id005
94
+ prerelease: false
67
95
  - !ruby/object:Gem::Dependency
68
96
  type: :development
69
- prerelease: false
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
70
106
  name: rcov
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
107
+ version_requirements: *id006
108
+ prerelease: false
109
+ - !ruby/object:Gem::Dependency
110
+ type: :development
111
+ requirement: &id007 !ruby/object:Gem::Requirement
72
112
  none: false
73
113
  requirements:
74
114
  - - ">="
@@ -77,12 +117,26 @@ dependencies:
77
117
  segments:
78
118
  - 0
79
119
  version: "0"
80
- requirement: *id004
120
+ name: ruby-debug
121
+ version_requirements: *id007
122
+ prerelease: false
81
123
  - !ruby/object:Gem::Dependency
82
- type: :runtime
124
+ type: :development
125
+ requirement: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ name: pry
135
+ version_requirements: *id008
83
136
  prerelease: false
84
- name: gmail
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
137
+ - !ruby/object:Gem::Dependency
138
+ type: :runtime
139
+ requirement: &id009 !ruby/object:Gem::Requirement
86
140
  none: false
87
141
  requirements:
88
142
  - - ">="
@@ -93,7 +147,9 @@ dependencies:
93
147
  - 4
94
148
  - 0
95
149
  version: 0.4.0
96
- requirement: *id005
150
+ name: gmail
151
+ version_requirements: *id009
152
+ prerelease: false
97
153
  description: The original Otherinbox Defender is no more. Sadly, the newest version is subpar and do not meet my needs. This project attempts to reproduce the core functionalities of OIB Defender using a GMail account.
98
154
  email: caffeine@gmail.com
99
155
  executables:
@@ -104,8 +160,8 @@ extra_rdoc_files:
104
160
  - LICENSE.txt
105
161
  - README.rdoc
106
162
  files:
107
- - .document
108
163
  - Gemfile
164
+ - Gemfile.lock
109
165
  - LICENSE.txt
110
166
  - README.rdoc
111
167
  - Rakefile
@@ -145,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
201
  requirements: []
146
202
 
147
203
  rubyforge_project:
148
- rubygems_version: 1.3.7
204
+ rubygems_version: 1.5.3
149
205
  signing_key:
150
206
  specification_version: 3
151
207
  summary: gmail based otherinbox defender alternative
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt