baconmail 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ .idea/.name
2
+ .idea/.rakeTasks
3
+ .idea/encodings.xml
4
+ .idea/misc.xml
5
+ .idea/modules.xml
6
+ .idea/scopes/scope_settings.xml
7
+ .idea/src.iml
8
+ .idea/vcs.xml
9
+ .idea/workspace.xml
10
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "aws-s3"
4
+ gem "gmail"
5
+
6
+ group :development do
7
+ gem "shoulda"
8
+ gem "bundler"
9
+ gem "pry"
10
+ end
11
+
12
+ gemspec
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ baconmail (0.9.0)
5
+ aws-s3
6
+ gmail (>= 0.4.0)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.9)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ aws-s3 (0.6.3)
15
+ builder
16
+ mime-types
17
+ xml-simple
18
+ builder (3.1.4)
19
+ coderay (1.0.8)
20
+ gmail (0.4.0)
21
+ gmail_xoauth (>= 0.3.0)
22
+ mail (>= 2.2.1)
23
+ mime (>= 0.1)
24
+ gmail_xoauth (0.4.1)
25
+ oauth (>= 0.3.6)
26
+ i18n (0.6.1)
27
+ mail (2.5.2)
28
+ i18n (>= 0.4.0)
29
+ mime-types (~> 1.16)
30
+ treetop (~> 1.4.8)
31
+ method_source (0.8.1)
32
+ mime (0.1)
33
+ mime-types (1.19)
34
+ multi_json (1.3.7)
35
+ oauth (0.4.7)
36
+ polyglot (0.3.3)
37
+ pry (0.9.10)
38
+ coderay (~> 1.0.5)
39
+ method_source (~> 0.8)
40
+ slop (~> 3.3.1)
41
+ shoulda (3.3.2)
42
+ shoulda-context (~> 1.0.1)
43
+ shoulda-matchers (~> 1.4.1)
44
+ shoulda-context (1.0.1)
45
+ shoulda-matchers (1.4.1)
46
+ activesupport (>= 3.0.0)
47
+ slop (3.3.3)
48
+ treetop (1.4.12)
49
+ polyglot
50
+ polyglot (>= 0.3.1)
51
+ xml-simple (1.1.2)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ aws-s3
58
+ baconmail!
59
+ bundler
60
+ gmail
61
+ pry
62
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 rodrigo franco (caffo)
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,66 @@
1
+ = Baconmail
2
+
3
+ By Rodrigo Franco and Marcos Tapajos
4
+
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
+
7
+ * Emails are automatically labeled by mailbox name
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 the day before
10
+ * Emails previews can be generated, so you can easily see yesterday messages without login into your baconmail mailbox. (Optional)
11
+
12
+ == Getting started (Pre-requisites)
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)
15
+ * Setup one email account on it
16
+ * {Configure the email account}[http://www.google.com/support/a/bin/answer.py?hl=en&answer=33962] as catch all. Make sure everything works properly
17
+ * Enable the ‘Hide Read Labels’ labs feature
18
+ * Make sure you disable the ‘Nested Labels’ labs feature – its know to generate performance issues if you have a lot of labels
19
+ * To better replicate the defender concept, disable the spam filter following {this instructions}[http://www.mydigitallife.info/2008/11/24/how-to-disable-and-deactivate-spam-filter-protection-in-gmail-or-google-mail/]
20
+
21
+ == Setup instructions
22
+ * Install the gem as usual:
23
+
24
+ $ gem install baconmail
25
+
26
+ * Create a .baconmail file in your home directory. It should look like this:
27
+
28
+ accounts:
29
+ - username: caconmail@gmail.com
30
+ password: password42
31
+ email: personal@email.com
32
+
33
+ - username: anotherbaconmail@gmail.com
34
+ password: password42!
35
+ email: personal2@email.com
36
+
37
+ config:
38
+ use_preview: false
39
+ bucket: baconmail.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).
45
+
46
+ * Add the following lines to your cron tab:
47
+
48
+ */5 * * * * baconmail process
49
+ 55 04 * * * baconmail digest
50
+
51
+ That will ensure the script organizes your mailbox each 5 minutes. It will also send you the daily digest at 04:55am.
52
+
53
+ == Contributing to baconmail
54
+
55
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
56
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
57
+ * Fork the project
58
+ * Start a feature/bugfix branch
59
+ * Commit and push until you are happy with your contribution
60
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
61
+ * 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.
62
+
63
+ == Copyright
64
+
65
+ Copyright (c) 2011 rodrigo franco (caffo). See LICENSE.txt for further details.
66
+
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
8
+
9
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
10
+ spec.rcov = true
11
+ end
12
+
13
+ require 'rake/rdoctask'
14
+ Rake::RDocTask.new do |rdoc|
15
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
16
+
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = "redfinger #{version}"
19
+ rdoc.rdoc_files.include('README*')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
@@ -0,0 +1,23 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'baconmail'
6
+ s.version = Baconmail::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+
9
+ s.authors = ["rodrigo franco (caffo)"]
10
+ s.email = ['baconmail@caffo.me']
11
+ s.homepage = 'http://github.com/caffo/baconmail'
12
+ s.summary = 'gmail based otherinbox defender alternative'
13
+ s.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.'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.extra_rdoc_files = %w[ LICENSE.txt README.rdoc ]
18
+ s.require_paths = %w[ lib ]
19
+
20
+ s.add_runtime_dependency 'gmail', ">= 0.4.0"
21
+ s.add_runtime_dependency 'aws-s3'
22
+ end
23
+
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require 'rubygems'
6
+ require 'yaml'
7
+ require 'baconmail'
8
+
9
+ if ARGV[0]
10
+ settings = YAML::load(File.open("#{ENV['HOME']}/.baconmail"))
11
+ case ARGV[0]
12
+ when "process"
13
+ settings["accounts"].each do |s|
14
+ Baconmail.process_inbox!(s["username"],
15
+ s["password"],
16
+ s["email"])
17
+ end
18
+ when "digest"
19
+ settings["accounts"].each do |s|
20
+ Baconmail.daily_digest(s["username"],
21
+ s["password"],
22
+ s["email"],
23
+ settings["config"])
24
+ end
25
+ end
26
+ else
27
+ puts "baconmail [process | digest]"
28
+ end
@@ -0,0 +1,132 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'gmail'
4
+ require 'logger'
5
+ require 'date'
6
+ require 'digest/sha1'
7
+ require 'aws/s3'
8
+
9
+ class Baconmail < Object
10
+ def self.process_inbox!(email_address, password, target_email)
11
+ log = Logger.new(STDOUT)
12
+ log.info("Account: #{email_address}")
13
+ Gmail.new(email_address, password) do |gmail|
14
+ gmail.inbox.emails(:unread).each do |email|
15
+ mailbox = email[:to].detect{|mail| mail.host == email_address.split("@").last}.mailbox.downcase rescue "unknown"
16
+ gmail.labels.new(mailbox)
17
+ if gmail.mailbox(mailbox).count == 0
18
+ log.info("First email for [#{gmail.mailbox(mailbox)}], forwarding..")
19
+ fwd = gmail.message
20
+ fwd.to = target_email
21
+ fwd.subject = "New Sender: #{email.subject}"
22
+ fwd.content_type = "text/html"
23
+ body = email.parts.last.body.to_s rescue nil
24
+ body ||= email.body.to_s
25
+ fwd.body = "-------------------------- BACONMAIL ----------------------------------<br/>
26
+ You have received a message from : #{mailbox}<br/>
27
+ We have created a new label : #{mailbox}<br/>
28
+ -------------------------- BACONMAIL ----------------------------------<br/><br/>" + body
29
+ fwd.deliver!
30
+ end
31
+ email.label(mailbox)
32
+ email.unread!
33
+ email.archive!
34
+ log.info("\tProcessing #{email[:subject]}")
35
+ end
36
+ end
37
+ log.info("Process finished")
38
+ end
39
+
40
+ def self.daily_digest(email_address, password, target_email, configs)
41
+ log = Logger.new(STDOUT)
42
+ emails = []
43
+ aib_domain = email_address.split("@")[1]
44
+
45
+ log.info("Account: #{email_address}")
46
+
47
+ Gmail.new(email_address, password) do |gmail|
48
+ gmail.mailbox('[Gmail]/All Mail').emails(:on => (Date.today - 1)).each do |email|
49
+
50
+ next if email.subject.match("Daily Digest for") rescue nil
51
+ next if "#{email.from[0]['mailbox']}@#{email.from[0]['host']}" == email_address
52
+
53
+ mailbox = email[:to][0].mailbox.downcase rescue "unknown"
54
+ body = email.html_part.nil? ? email.body : email.html_part.body
55
+ emails << [mailbox, email.subject, body]
56
+ end
57
+
58
+ if emails.size > 0
59
+ if configs["use_preview"]
60
+ log.info("Generating previews...")
61
+ self.generate_previews(emails, configs, email_address)
62
+ end
63
+
64
+ log.info("Sending daily digest with #{emails.size} entries..")
65
+ digest = gmail.message
66
+ digest.to = target_email
67
+ digest.subject = "[#{aib_domain}] Bacon Mail for #{(Date.today - 1)}"
68
+ digest.content_type = "text/html"
69
+ digest.body = self.email_template(emails, aib_domain, configs, email_address)
70
+ digest.deliver!
71
+ end
72
+ end
73
+ log.info("Process finished")
74
+ end
75
+
76
+ def self.email_template(new_messages, account, configs, email_address)
77
+ # we all know, inline styles sucks. sadly, it's the
78
+ # only way to get them into gmail.
79
+ response = ""
80
+ response += "<h1 style='margin-left: 40px; color: #DC6582;'>Bacon Mail for #{(Date.today - 1)}</h1>"
81
+ response += "<h3 style='color: #F59FAC; margin-left: 40px; margin-top: -10px; margin-bottom: 30px;'>for <a href='http://#{account}' style='color: #F59FAC;'>#{account}</a></h3>"
82
+ response += "<ul style='width: 90%;'>"
83
+
84
+ new_messages.sort_by{|x| x[0]}.each do |m|
85
+ response += "<li style='margin-bottom: 10px; list-style: none; color: #DC6582; border-bottom: 1px dotted #ccc; padding-bottom: 10px; font-weight: bold;'>"
86
+ response += m[0]
87
+ response += ": <strong style='color: #000000; font-weight: normal;'>"
88
+
89
+ if configs["use_preview"]
90
+ response += "<a href='http://"
91
+ response += configs["bucket"]
92
+ response += ".s3.amazonaws.com/"
93
+ response += email_address.gsub("@", "_").gsub(".", "_")
94
+ response += "_"
95
+ response += Digest::SHA1.hexdigest(m[1])
96
+ response += ".html' style='color: #000;'>#{m[1]}</a>"
97
+ else
98
+ response += m[1]
99
+ end
100
+
101
+ response += "</li>"
102
+ end
103
+
104
+ response += "</ul>"
105
+ return response
106
+ end
107
+
108
+ def self.generate_previews(new_messages, configs, email_address)
109
+ AWS::S3::Base.establish_connection!(
110
+ :access_key_id => configs["aws_key"],
111
+ :secret_access_key => configs["aws_secret"]
112
+ )
113
+
114
+ # set file prefix. useful when we have more than one
115
+ # baconmail account running in the same script instance
116
+ prefix = email_address.gsub("@", "_").gsub(".", "_")
117
+
118
+ #binding.pry
119
+
120
+ # cleanup the bucket
121
+ while (AWS::S3::Bucket.objects(configs["bucket"], :prefix => prefix).size > 0) do
122
+ AWS::S3::Bucket.objects(configs["bucket"]).each do |file|
123
+ file.delete if file.key.match(prefix)
124
+ end
125
+ end
126
+
127
+ new_messages.sort_by{|x| x[0]}.each do |m|
128
+ filename = Digest::SHA1.hexdigest(m[1])
129
+ AWS::S3::S3Object.store("#{prefix}_#{filename}.html", m[2].to_s, configs["bucket"], :access => :public_read)
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,3 @@
1
+ module Baconmail
2
+ VERSION = "0.9.0"
3
+ end
@@ -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 'baconmail'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestBaconMail < 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,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: baconmail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - rodrigo franco (caffo)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gmail
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: aws-s3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: The original Otherinbox Defender is no more. Sadly, the newest version
47
+ is subpar and do not meet my needs. This project attempts to reproduce the core
48
+ functionalities of OIB Defender using a GMail account.
49
+ email:
50
+ - baconmail@caffo.me
51
+ executables:
52
+ - baconmail
53
+ extensions: []
54
+ extra_rdoc_files:
55
+ - LICENSE.txt
56
+ - README.rdoc
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - LICENSE.txt
62
+ - README.rdoc
63
+ - Rakefile
64
+ - baconmail.gemspec
65
+ - bin/baconmail
66
+ - lib/baconmail.rb
67
+ - lib/version.rb
68
+ - test/helper.rb
69
+ - test/test_baconmail.rb
70
+ homepage: http://github.com/caffo/baconmail
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.24
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: gmail based otherinbox defender alternative
94
+ test_files: []