ultra7 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7121700c94f787f5218730614a249883d66d098c
4
- data.tar.gz: db87d3c8bfdc8db93474369d6606b78b5a84be3c
3
+ metadata.gz: 555011104f1136cd2db5802f51321b784a79bf3d
4
+ data.tar.gz: 49de6c0f2744b7b1fdb6f2053c775a0b689ac699
5
5
  SHA512:
6
- metadata.gz: 96fa90813ce6cc1d349963d988ac06b6c3575bdff0c9d3a74b20c17e8f504bc8c867dccc915ac949d4a05acaef4440bd9186dec4d2c424f24183b6dbfb487f4c
7
- data.tar.gz: ad4ebc79b09bf2f2f094551e5bdc9e989862ca7687399ecb89e90791a637eca8c17509b81654401ebe35129a169f7965ac52d8f9fbc9e5f072845cc2ccebd111
6
+ metadata.gz: 5a6bf087db91087c18ea8b469208d7eb314f526456b73dc62d5ee02e5c924c3698a190c9ab284a188be73ac39d1827b562a7825348c126a01f99ee5eae52ebd9
7
+ data.tar.gz: 40e87e21c246626f03b33c7b86b6fb815e03a4a51f9051fe51fecdd35beb492b707bd092fc1c996dc7b184358b9c2065f48376c20209d5949643145a51e8ee7b
data/CHANGELOG CHANGED
@@ -1,4 +1,10 @@
1
1
  ## CHANGELOG
2
2
 
3
- - __2014/12/12__: 0.1.0 release.
3
+
4
+ - __2014/12/14__: 0.2.0 release.
5
+ - Enhancements to deal with encoding marker.
6
+ - Raise ArgumentError when non-UTF-7 encoding marker text is passed in.
7
+ - Added more tests.
8
+
9
+ - __2014/12/13__: 0.1.0 release.
4
10
  - Initial release
data/README.md CHANGED
@@ -1,47 +1,58 @@
1
1
  # Ultra7
2
- A UTF-7 MIME decoder, plain and simple.
2
+ A UTF-7 MIME header decoder, plain and simple.
3
3
 
4
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
5
 
10
- You can learn more about [Ultra7 at bitbucket](https://bitbucket.org/buruzaemon/ultra7/).
6
+ * Ultra7 is a UTF-7 decoder for MIME headers, unlike `Net::IMAP.decode_utf7`
7
+ which is meant for decoding mailbox names.
8
+ * `Ultra7::MIME` is also a a mixin, so you can conveniently combine it in another class by using
9
+ `include`.
10
+ * Read the [API documentation](http://www.rubydoc.info/gems/ultra7).
11
+ * Learn more about [Ultra7 at bitbucket](https://bitbucket.org/buruzaemon/ultra7/).
11
12
 
12
13
 
13
14
  ## 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
15
 
20
- gem install ultra7
16
+ * Ultra7 does not really require anything, except a Ruby of _1.9 or greater_.
21
17
 
22
18
 
23
- ## Usage
24
- require 'ultra7'
19
+ ## Installation
25
20
 
26
- # just call decode_utf7
27
- puts Ultra7::MIME.decode_utf7('1 +- 1 = 2')
28
- => 1 + 1 = 2
21
+ * Install Ultra7 with the following gem command:
29
22
 
30
- # Decodes UTF-7, returning string with default encoding
31
- puts Ultra7::MIME.decode_utf7('Hello, +ZeVnLIqe-')
32
- => Hello, 日本語
23
+ gem install ultra7
33
24
 
34
- # Decodes UTF-7, returning string with explicit UTF-8 encoding
35
- Ultra7::MIME.decode_utf7('Hello, +ZeVnLIqe-', encoding: 'utf-8')
36
25
 
37
- # As a mixin to another class
38
- require 'ultra7/mime'
39
- class Foo
40
- include Ultra7::MIME
41
- end
26
+ ## Usage
42
27
 
43
- puts Foo.decode_utf7('1 +- 1 = 2')
44
- => 1 + 1 = 2
28
+ * Using Ultra7 is pretty straight-forward, really. It _only_ decode UTF-7.
29
+
30
+ require 'ultra7'
31
+
32
+ # just call decode_utf7
33
+ puts Ultra7::MIME.decode_utf7('1 +- 1 = 2')
34
+ => "1 + 1 = 2"
35
+
36
+ # Decodes UTF-7, returning string with default encoding
37
+ puts Ultra7::MIME.decode_utf7('Hello, +ZeVnLIqe-')
38
+ => "Hello, 日本語"
39
+
40
+ # Decodes an actual Subject MIME header in UTF-7,
41
+ # returning string with explicit UTF-8 encoding
42
+ subject = '=?unicode-1-1-utf-7?Q?+vDCy7A- +wMHQ3A- +xUy5vA-(+wuTTKA-)?='
43
+ Ultra7::MIME.decode_utf7(subject, encoding: 'UTF-8')
44
+ => "배달 상태 알림(실패)"
45
+
46
+ * And you can use `Ultra7::MIME` as a mixin.
47
+
48
+ # As a mixin to another class
49
+ require 'ultra7/mime'
50
+ class Foo
51
+ include Ultra7::MIME
52
+ end
53
+
54
+ puts Foo.decode_utf7('Hi Mom -+Jjo--!')
55
+ => "Hi Mom -☺-!"
45
56
 
46
57
 
47
58
  ## Learn more
@@ -10,15 +10,27 @@ module Ultra7
10
10
 
11
11
  # Returns the decoded value for the given
12
12
  # UTF-7 encoded `text`. If the optional
13
- # `encoding` value is not specified, then
14
- # the resulting string will use the default
13
+ # `encoding` value is not specified, in the `options`
14
+ # hash, then the resulting string will use the default
15
15
  # `Encoding.default_external` encoding.
16
16
  #
17
17
  # @param [String] UTF-7 encoded text
18
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={})
19
+ # @return [String] UTF-7 decoded value
20
+ # @raise [ArgumentError] if text other than UTF-7 are passed in, or the given `encoding` cannot be found
21
+ # convert UTF-7
22
+ def self.decode_utf7(text, options={encoding: nil})
23
+ # only deal with UTF-7 encoding
24
+ text.scan(/=\?(.*)\?[qb]\?/i).each {
25
+ e = $1
26
+ if e and !(e=~/utf\-7/i)
27
+ raise ArgumentError.new("Cannot decode #{e} as UTF-7!")
28
+ end
29
+ }
30
+
31
+ # remove any encoding start/end markers
32
+ text = text.gsub(/\?=/, '').gsub(/=\?[^?]*utf\-7\?[qb]\?/i, '')
33
+
22
34
  enc = options[:encoding].nil? \
23
35
  ? Encoding.default_external \
24
36
  : Encoding.find(options[:encoding])
@@ -7,7 +7,7 @@
7
7
  # It may be used as a mixin.
8
8
  module Ultra7
9
9
  # Version string for this Rubygem.
10
- VERSION = "0.1.0"
10
+ VERSION = "0.2.0"
11
11
  end
12
12
 
13
13
  # Copyright (c) 2014-2015, Brooke M. Fujita.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra7
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke M. Fujita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  ultra7 decodes UTF-7 in the context of MIME headers (c.f. https://tools.ietf.org/html/rfc2152).
@@ -47,5 +47,5 @@ rubyforge_project:
47
47
  rubygems_version: 2.4.1
48
48
  signing_key:
49
49
  specification_version: 4
50
- summary: A UTF-7 MIME decoder, plain and simple.
50
+ summary: A UTF-7 MIME header decoder, plain and simple.
51
51
  test_files: []