gmail_compose_encoder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c590293b67a0f604a2d149fa5fee97c23a6b9432
4
+ data.tar.gz: f00d9a3d03e9038883a0c51dd4fab90d37d3eb45
5
+ SHA512:
6
+ metadata.gz: 48f36b0138b529dc9b636f575f338bd53873ee3e8230c1a0145e6ff4f23ace86f71338027302607e932361817482b68dcf0f5a4bf938d5cd3843259fea29f42f
7
+ data.tar.gz: ce177dafccb05aa1432e517b947f484b31d958d956f9d89b69df434ba33a12b61420a61157b9da35061f39b132bdf4718ba93513aedd0f11fd760d4e2ab289a0
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.1
7
+ before_install: gem install bundler -v 1.16.5
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rob.mathews@goodmeasures.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gmail_compose_encoder.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gmail_compose_encoder (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.8.0)
12
+ rspec-core (~> 3.8.0)
13
+ rspec-expectations (~> 3.8.0)
14
+ rspec-mocks (~> 3.8.0)
15
+ rspec-core (3.8.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-expectations (3.8.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.8.0)
20
+ rspec-mocks (3.8.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.8.0)
23
+ rspec-support (3.8.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ gmail_compose_encoder!
31
+ rake (~> 10.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.5
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 rob mathews
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,62 @@
1
+ # GmailComposeEncoder
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gmail_compose_encoder`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ gmail_compose_encoder is a ruby implementation of googles - specifically gmails - url encoding scheme for opening the gmail in "compose message" mode on a particular draft email.
6
+
7
+ In particular, it is the ruby answer to this question:
8
+
9
+ What do I put into the URI querystring of the new Gmail UI to view a draft message created by the Gmail API?
10
+
11
+ --
12
+
13
+ If I view a draft message in the new Gmail UI, the URI is something like this:
14
+
15
+ https://mail.google.com/mail/u/1/?zx=iij9apqgzdf4#drafts?compose=jrjtXSqXwlFGnSGCQgDCdnHGVFdlpFMgzsCNgpQstQLxdLCMkjKstBmWZkCmjhWTQnpsZCJF
16
+
17
+ Specifically, referenced in this SO article https://stackoverflow.com/questions/50124112/how-does-a-gmail-message-id-or-threadid-map-to-the-new-gmail-ui
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'gmail_compose_encoder'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install gmail_compose_encoder
33
+
34
+ ## Usage
35
+ depends on the google-apis gem, you'd use it something like this:
36
+ ```ruby
37
+ # assume gmail_authorization_token is your GoogleOauthToken,
38
+ # and you've created gmail_draft_id via the API.
39
+ draft = gmail_authorization_token.with_gmail_service do |client|
40
+ client.get_user_draft('me', gmail_draft_id)
41
+ end
42
+ # then this call creates a url that you can use in the browser to open
43
+ # a gmail tab with the draft opened in compose mode
44
+ GmailComposeEncoder.compose_draft_url(from_address, draft.message.thread_id, draft.message.id)
45
+ ```
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gmail_compose_encoder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
59
+
60
+ ## Code of Conduct
61
+
62
+ Everyone interacting in the GmailComposeEncoder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gmail_compose_encoder/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gmail_compose_encoder"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gmail_compose_encoder/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gmail_compose_encoder"
8
+ spec.version = GmailComposeEncoder::VERSION
9
+ spec.authors = ["rob mathews"]
10
+ spec.email = ["rob.mathews@goodmeasures.com"]
11
+
12
+ spec.summary = %q{create the 'open a draft email in compose mode' url for the new gmail client}
13
+ spec.description = %q{
14
+ gmail_compose_encoder is a ruby implementation of googles - specifically gmails - url encoding scheme for opening the gmail in "compose message" mode on a particular draft email.
15
+
16
+ In particular, it is the ruby answer to this question:
17
+
18
+ What do I put into the URI querystring of the new Gmail UI to view a draft message created by the Gmail API?
19
+ }
20
+ spec.homepage = ""
21
+ spec.license = "MIT"
22
+
23
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ end
@@ -0,0 +1,9 @@
1
+ require "gmail_compose_encoder/version"
2
+ require 'gmail_compose_encoder/encoder'
3
+
4
+ module GmailComposeEncoder
5
+ def self.compose_draft_url(from_address, thread_id, message_id)
6
+ tmp=encode("thread-f:#{thread_id.to_i(16)}+msg-a:#{message_id}")
7
+ "https://mail.google.com/mail/u/#{from_address}/#all?compose=#{tmp}"
8
+ end
9
+ end
@@ -0,0 +1,56 @@
1
+ require 'base64'
2
+ module GmailComposeEncoder
3
+
4
+ FULL_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5
+ RESTRICTED_ALPHABET = 'BCDFGHJKLMNPQRSTVWXZbcdfghjklmnpqrstvwxz';
6
+ THREAD_PREFIX = 'thread-';
7
+ MESSAGE_PREFIX = 'msg-';
8
+
9
+ # for whatever reason, google choose to Base64.encode64 the string, and then further
10
+ # map it into a restricted alphabet with no vowels or numbers.
11
+ def self.encode(url_parameter)
12
+ transliterate(Base64.strict_encode64(url_parameter.gsub(THREAD_PREFIX,'')).gsub(/=/,''), FULL_ALPHABET, RESTRICTED_ALPHABET)
13
+ end
14
+
15
+ def self.transliterate(string, input_alphabet=FULL_ALPHABET, output_alphabet=RESTRICTED_ALPHABET)
16
+ string_indices = string.chars.reverse.map {|char| input_alphabet.index(char)}
17
+ # string_indices.each {|xxx| puts "inputIndices #{xxx}"}
18
+ result_indices = []
19
+ string_indices.reverse.each_with_index do |string_index,iii|
20
+ offset=0
21
+ result_indices.each.with_index do |result_index,j|
22
+ index = result_index * input_alphabet.size + offset
23
+ if(index >=input_alphabet.size)
24
+ remainder = index % output_alphabet.size
25
+ offset = (index - remainder) / output_alphabet.size
26
+ index=remainder
27
+ else
28
+ offset = 0
29
+ end
30
+ result_indices[j]=index
31
+ end
32
+ while(!offset.zero?)
33
+ remainder = offset % output_alphabet.size
34
+ result_indices.push(remainder)
35
+ offset = (offset - remainder) / output_alphabet.size
36
+ end
37
+ jjj=0
38
+ offset=string_index
39
+ while(!offset.zero?)
40
+ result_indices[jjj] = 0 if result_indices[jjj].nil?
41
+ index = result_indices[jjj] + offset
42
+ if(index >=output_alphabet.size)
43
+ remainder = index % output_alphabet.size
44
+ offset = (index - remainder) / output_alphabet.size
45
+ result_indices[jjj]=remainder
46
+ else
47
+ offset=0
48
+ result_indices[jjj]=index
49
+ end
50
+ jjj+=1
51
+ end
52
+ end
53
+
54
+ result_indices.reverse.map {|idx| output_alphabet[idx]}.join
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module GmailComposeEncoder
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gmail_compose_encoder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - rob mathews
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: "\ngmail_compose_encoder is a ruby implementation of googles - specifically
56
+ gmails - url encoding scheme for opening the gmail in \"compose message\" mode on
57
+ a particular draft email.\n\nIn particular, it is the ruby answer to this question:\n\nWhat
58
+ do I put into the URI querystring of the new Gmail UI to view a draft message created
59
+ by the Gmail API?\n "
60
+ email:
61
+ - rob.mathews@goodmeasures.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - ".gitignore"
67
+ - ".rspec"
68
+ - ".travis.yml"
69
+ - CODE_OF_CONDUCT.md
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - bin/console
76
+ - bin/setup
77
+ - gmail_compose_encoder.gemspec
78
+ - lib/gmail_compose_encoder.rb
79
+ - lib/gmail_compose_encoder/encoder.rb
80
+ - lib/gmail_compose_encoder/version.rb
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: create the 'open a draft email in compose mode' url for the new gmail client
105
+ test_files: []