Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
source "http://rubygems.org"

gem "aws-s3"
gem "gmail"
gem 'google-api-client', '~> 0.11'

group :development do
gem "shoulda"
gem "bundler"
gem "pry"
gem "rspec"
end
Expand Down
95 changes: 57 additions & 38 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,63 @@ PATH
GEM
remote: http://rubygems.org/
specs:
activesupport (3.2.9)
i18n (~> 0.6)
multi_json (~> 1.0)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
aws-s3 (0.6.3)
builder
mime-types
xml-simple
builder (3.1.4)
coderay (1.0.8)
builder (3.2.3)
coderay (1.1.2)
declarative (0.0.10)
declarative-option (0.1.0)
diff-lcs (1.3)
gmail (0.4.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
gmail (0.7.1)
gmail_xoauth (>= 0.3.0)
mail (>= 2.2.1)
mime (>= 0.1)
gmail_xoauth (0.4.1)
gmail_xoauth (0.4.2)
oauth (>= 0.3.6)
i18n (0.6.1)
mail (2.5.2)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.1)
mime (0.1)
mime-types (1.19)
multi_json (1.3.7)
oauth (0.4.7)
polyglot (0.3.3)
pry (0.9.10)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
rake (10.0.3)
google-api-client (0.28.7)
addressable (~> 2.5, >= 2.5.1)
googleauth (>= 0.5, < 0.10.0)
httpclient (>= 2.8.1, < 3.0)
mime-types (~> 3.0)
representable (~> 3.0)
retriable (>= 2.0, < 4.0)
signet (~> 0.10)
googleauth (0.8.1)
faraday (~> 0.12)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (~> 0.7)
httpclient (2.8.3)
jwt (2.1.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
memoist (0.16.0)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mini_mime (1.0.1)
multi_json (1.13.1)
multipart-post (2.0.0)
oauth (0.5.4)
os (1.0.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.3)
rake (12.3.2)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
Expand All @@ -53,30 +78,24 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
shoulda (3.3.2)
shoulda-context (~> 1.0.1)
shoulda-matchers (~> 1.4.1)
shoulda-context (1.0.1)
shoulda-matchers (1.4.1)
activesupport (>= 3.0.0)
slop (3.3.3)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
xml-simple (1.1.2)
signet (0.11.0)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
uber (0.1.0)
xml-simple (1.1.5)

PLATFORMS
ruby

DEPENDENCIES
aws-s3
baconmail!
bundler
gmail
google-api-client (~> 0.11)
pry
rake
rspec
shoulda

BUNDLED WITH
1.17.2
6 changes: 4 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,24 @@ The original {Otherinbox Defender}[http://mashable.com/2008/09/08/otherinbox/] i

$ gem install baconmail

* Obtain Gmail OAuth credentials for console application using {the wizard}[https://console.developers.google.com/flows/enableapi?apiid=gmail&pli=1].

* Create a .baconmail file in your home directory. It should look like this:

accounts:
- username: caconmail@gmail.com
password: password42
email: personal@email.com

- username: anotherbaconmail@gmail.com
password: password42!
email: personal2@email.com

config:
use_preview: false
bucket: baconmail.amazon.bucket
aws_key: KEY-GOES-HERE
aws_secret: SECRET-GOES-HERE
google_client_id: ID-GOES-HERE
google_client_secret: SECRET-GOES-HERE

blacklist:
- amazon
Expand Down
10 changes: 7 additions & 3 deletions bin/baconmail
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ if ARGV[0]
end
when "digest"
Baconmail::Settings.instance.accounts.each do |account|
Baconmail::Digest.new(account, Baconmail::Settings.instance.config).daily_digest
Baconmail::Digest.new(account).daily_digest
end
when "authorize"
Baconmail::Settings.instance.accounts.each do |account|
Baconmail::Authorizer.call(account.username)
end
end
else
puts "baconmail [process | digest]"
end
puts "baconmail [process | digest | authorize]"
end
23 changes: 21 additions & 2 deletions lib/baconmail.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# encoding: UTF-8
require 'gmail'
require 'google/apis/gmail_v1'
require 'logger'
require 'date'
require 'mail'
require 'digest/sha1'
require 'aws/s3'
require 'yaml'
require 'singleton'
require 'baconmail/object'
require 'baconmail/service'
require 'baconmail/account'
require 'baconmail/authorizer'
require 'baconmail/config'
require 'baconmail/settings'
require 'baconmail/inbox'
require 'baconmail/digest'
require 'baconmail/digest'

module Baconmail
Gmail = Google::Apis::GmailV1

def self.logger
@logger ||= Logger.new(STDOUT)
end

def self.authorized_gmail(username)
Gmail::GmailService.new.tap do |g|
g.authorization = Authorizer.credentials(username)
g.client_options.application_name = 'Baconmail'
end
end
end
2 changes: 1 addition & 1 deletion lib/baconmail/account.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: UTF-8
module Baconmail
Account = Struct.new(:username, :password, :email)
Account = Struct.new(:username, :email)
end
56 changes: 56 additions & 0 deletions lib/baconmail/authorizer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# require 'google/api_client/client_secrets'
require 'googleauth/stores/file_token_store'

# encoding: UTF-8
module Baconmail
class Authorizer
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
SCOPE = Google::Apis::GmailV1::AUTH_SCOPE

class << self
def call(user_id)
raise "Google Client ID or Google Client Secret are invalid." if invalid_keys?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I try to run bin/baconmail authorize I get the following error:

baconmail/lib/baconmail/authorizer.rb:12:in `call': Google Client ID or Google Client Secret are invalid. (RuntimeError)

I think you are checking if the keys are invalid before we fetch them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caffo hmm, did you add the keys to .baconmail? See an example in README: https://github.com/mbirman/baconmail/tree/google-api-client#setup-instructions


credentials(user_id) || fetch_credentials(user_id)
end

def credentials(user_id)
authorizer.get_credentials(user_id)
end

def fetch_credentials(user_id)
Baconmail.logger.info "Open the following URL in your browser, log in to #{user_id} and authorize the application."
Baconmail.logger.info authorization_url
Baconmail.logger.info "Enter the authorization code:"

code = STDIN.gets.chomp

authorizer.get_and_store_credentials_from_code(user_id: user_id, code: code, base_url: OOB_URI)
end

def authorizer
Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store)
end

def client_id
Google::Auth::ClientId.new(config.google_client_id, config.google_client_secret)
end

def token_store
Google::Auth::Stores::FileTokenStore.new(file: Baconmail::Settings::BACONMAIL_CONFIG_PATH)
end

def authorization_url
authorizer.get_authorization_url(base_url: OOB_URI)
end

def invalid_keys?
"#{config.google_client_id}".empty? || "#{config.google_client_secret}".empty?
end

def config
Baconmail::Settings.instance.config
end
end
end
end
7 changes: 5 additions & 2 deletions lib/baconmail/config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# encoding: UTF-8
module Baconmail
Config = Struct.new(:use_preview, :bucket, :aws_key, :aws_secret)
end
Config = Struct.new(
:use_preview, :bucket, :aws_key, :aws_secret,
:google_client_id, :google_client_secret
)
end
Loading