ultra7 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +7 -0
- data/CHANGELOG +4 -0
- data/LICENSE +26 -0
- data/README.md +65 -0
- data/lib/ultra7/mime.rb +74 -0
- data/lib/ultra7/version.rb +38 -0
- data/lib/ultra7.rb +27 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7121700c94f787f5218730614a249883d66d098c
|
4
|
+
data.tar.gz: db87d3c8bfdc8db93474369d6606b78b5a84be3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96fa90813ce6cc1d349963d988ac06b6c3575bdff0c9d3a74b20c17e8f504bc8c867dccc915ac949d4a05acaef4440bd9186dec4d2c424f24183b6dbfb487f4c
|
7
|
+
data.tar.gz: ad4ebc79b09bf2f2f094551e5bdc9e989862ca7687399ecb89e90791a637eca8c17509b81654401ebe35129a169f7965ac52d8f9fbc9e5f072845cc2ccebd111
|
data/.yardopts
ADDED
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2014-2015, Brooke M. Fujita.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above
|
8
|
+
copyright notice, this list of conditions and the
|
9
|
+
following disclaimer.
|
10
|
+
|
11
|
+
* Redistributions in binary form must reproduce the above
|
12
|
+
copyright notice, this list of conditions and the
|
13
|
+
following disclaimer in the documentation and/or other
|
14
|
+
materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
20
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
21
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
26
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Ultra7
|
2
|
+
A UTF-7 MIME decoder, plain and simple.
|
3
|
+
|
4
|
+
## What is Ultra7?
|
5
|
+
Ultra7 is a UTF-7 decoder for MIME headers, unlike `Net::IMAP.decode_utf7`
|
6
|
+
which is meant for decoding mailbox names. `Ultra7::MIME` is also a
|
7
|
+
a mixin, so you can conveniently combine it in another class by using
|
8
|
+
`include`.
|
9
|
+
|
10
|
+
You can learn more about [Ultra7 at bitbucket](https://bitbucket.org/buruzaemon/ultra7/).
|
11
|
+
|
12
|
+
|
13
|
+
## Requirements
|
14
|
+
Ultra7 does not really require anything, except a Ruby of _1.9 or greater_.
|
15
|
+
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
Install Ultra7 with the following gem command:
|
19
|
+
|
20
|
+
gem install ultra7
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
require 'ultra7'
|
25
|
+
|
26
|
+
# just call decode_utf7
|
27
|
+
puts Ultra7::MIME.decode_utf7('1 +- 1 = 2')
|
28
|
+
=> 1 + 1 = 2
|
29
|
+
|
30
|
+
# Decodes UTF-7, returning string with default encoding
|
31
|
+
puts Ultra7::MIME.decode_utf7('Hello, +ZeVnLIqe-')
|
32
|
+
=> Hello, 日本語
|
33
|
+
|
34
|
+
# Decodes UTF-7, returning string with explicit UTF-8 encoding
|
35
|
+
Ultra7::MIME.decode_utf7('Hello, +ZeVnLIqe-', encoding: 'utf-8')
|
36
|
+
|
37
|
+
# As a mixin to another class
|
38
|
+
require 'ultra7/mime'
|
39
|
+
class Foo
|
40
|
+
include Ultra7::MIME
|
41
|
+
end
|
42
|
+
|
43
|
+
puts Foo.decode_utf7('1 +- 1 = 2')
|
44
|
+
=> 1 + 1 = 2
|
45
|
+
|
46
|
+
|
47
|
+
## Learn more
|
48
|
+
- You can read more about UTF-7, A Mail-Safe Transformation Format of Unicode [RFC2152](https://tools.ietf.org/html/rfc2152).
|
49
|
+
- Contrast with
|
50
|
+
[`Net::IMAP.decode_utf7`](http://ruby-doc.org/stdlib-1.9.3/libdoc/net/imap/rdoc/Net/IMAP.html#method-c-decode_utf7).
|
51
|
+
|
52
|
+
## Contributing to natto
|
53
|
+
- Use [mercurial](http://mercurial.selenic.com/) and [check out the latest code at bitbucket](https://bitbucket.org/buruzaemon/ultra7/src/) to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
54
|
+
- [Browse the issue tracker](https://bitbucket.org/buruzaemon/ultra7/issues/) to make sure someone already hasn't requested it and/or contributed it.
|
55
|
+
- Fork the project.
|
56
|
+
- Start a feature/bugfix branch.
|
57
|
+
- Commit and push until you are happy with your contribution.
|
58
|
+
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. I use [MiniTest::Unit](http://rubydoc.info/gems/minitest/MiniTest/Unit) as it is very natural and easy-to-use.
|
59
|
+
- Please try not to mess with the Rakefile, CHANGELOG, or version. If you must have your own version, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
60
|
+
|
61
|
+
## Changelog
|
62
|
+
Please see the {file:CHANGELOG} for this gem's release history.
|
63
|
+
|
64
|
+
## Copyright
|
65
|
+
Copyright © 2014-2015, Brooke M. Fujita. All rights reserved. Please see the {file:LICENSE} file for further details.
|
data/lib/ultra7/mime.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module Ultra7
|
3
|
+
|
4
|
+
module MIME
|
5
|
+
|
6
|
+
# @private
|
7
|
+
def self.included(base)
|
8
|
+
base.extend(ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the decoded value for the given
|
12
|
+
# UTF-7 encoded `text`. If the optional
|
13
|
+
# `encoding` value is not specified, then
|
14
|
+
# the resulting string will use the default
|
15
|
+
# `Encoding.default_external` encoding.
|
16
|
+
#
|
17
|
+
# @param [String] UTF-7 encoded text
|
18
|
+
# @param [Hash] options
|
19
|
+
# @return UTF-7 decoded value
|
20
|
+
# @raise [ArgumentError] if the given `encoding` cannot be found
|
21
|
+
def self.decode_utf7(text, options={})
|
22
|
+
enc = options[:encoding].nil? \
|
23
|
+
? Encoding.default_external \
|
24
|
+
: Encoding.find(options[:encoding])
|
25
|
+
|
26
|
+
return text.gsub(/\+(.*?)-/n) {
|
27
|
+
if $1.empty?
|
28
|
+
"+"
|
29
|
+
else
|
30
|
+
base64 = $1
|
31
|
+
pad = base64.length % 4
|
32
|
+
if pad > 0
|
33
|
+
base64 << ("=" * (4-pad))
|
34
|
+
end
|
35
|
+
base64.unpack("m").first.unpack("n*").pack("U*")
|
36
|
+
end
|
37
|
+
}.encode(enc)
|
38
|
+
end
|
39
|
+
|
40
|
+
# @private
|
41
|
+
module ClassMethods
|
42
|
+
def decode_utf7(text, options={})
|
43
|
+
Ultra7::MIME.decode_utf7(text, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Copyright (c) 2014-2015, Brooke M. Fujita.
|
50
|
+
# All rights reserved.
|
51
|
+
#
|
52
|
+
# Redistribution and use in source and binary forms, with or without
|
53
|
+
# modification, are permitted provided that the following conditions are met:
|
54
|
+
#
|
55
|
+
# * Redistributions of source code must retain the above
|
56
|
+
# copyright notice, this list of conditions and the
|
57
|
+
# following disclaimer.
|
58
|
+
#
|
59
|
+
# * Redistributions in binary form must reproduce the above
|
60
|
+
# copyright notice, this list of conditions and the
|
61
|
+
# following disclaimer in the documentation and/or other
|
62
|
+
# materials provided with the distribution.
|
63
|
+
#
|
64
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
65
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
66
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
67
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
68
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
69
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
70
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
71
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
72
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
73
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
74
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# `Ultra7` is the namespace for objects that provide
|
4
|
+
# a UTF-7 MIME header decoding.
|
5
|
+
#
|
6
|
+
# Module `Ultra7::MIME` provides the UTF-7 decoder function.
|
7
|
+
# It may be used as a mixin.
|
8
|
+
module Ultra7
|
9
|
+
# Version string for this Rubygem.
|
10
|
+
VERSION = "0.1.0"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Copyright (c) 2014-2015, Brooke M. Fujita.
|
14
|
+
# All rights reserved.
|
15
|
+
#
|
16
|
+
# Redistribution and use in source and binary forms, with or without
|
17
|
+
# modification, are permitted provided that the following conditions are met:
|
18
|
+
#
|
19
|
+
# * Redistributions of source code must retain the above
|
20
|
+
# copyright notice, this list of conditions and the
|
21
|
+
# following disclaimer.
|
22
|
+
#
|
23
|
+
# * Redistributions in binary form must reproduce the above
|
24
|
+
# copyright notice, this list of conditions and the
|
25
|
+
# following disclaimer in the documentation and/or other
|
26
|
+
# materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
29
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
30
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
31
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
32
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
33
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
34
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
35
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
36
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
37
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
38
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
data/lib/ultra7.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ultra7/mime'
|
2
|
+
|
3
|
+
# Copyright (c) 2014-2015, Brooke M. Fujita.
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
7
|
+
# modification, are permitted provided that the following conditions are met:
|
8
|
+
#
|
9
|
+
# * Redistributions of source code must retain the above
|
10
|
+
# copyright notice, this list of conditions and the
|
11
|
+
# following disclaimer.
|
12
|
+
#
|
13
|
+
# * Redistributions in binary form must reproduce the above
|
14
|
+
# copyright notice, this list of conditions and the
|
15
|
+
# following disclaimer in the documentation and/or other
|
16
|
+
# materials provided with the distribution.
|
17
|
+
#
|
18
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
19
|
+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
22
|
+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
23
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24
|
+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
25
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ultra7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brooke M. Fujita
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |
|
14
|
+
ultra7 decodes UTF-7 in the context of MIME headers (c.f. https://tools.ietf.org/html/rfc2152).
|
15
|
+
email: buruzaemon@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .yardopts
|
21
|
+
- CHANGELOG
|
22
|
+
- LICENSE
|
23
|
+
- README.md
|
24
|
+
- lib/ultra7.rb
|
25
|
+
- lib/ultra7/mime.rb
|
26
|
+
- lib/ultra7/version.rb
|
27
|
+
homepage: https://bitbucket.org/buruzaemon/ultra7
|
28
|
+
licenses:
|
29
|
+
- BSD
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.9'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.4.1
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: A UTF-7 MIME decoder, plain and simple.
|
51
|
+
test_files: []
|