mail 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mail might be problematic. Click here for more details.

@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Mail #:nodoc:
4
- module Multibyte #:nodoc:
5
- # Raised when a problem with the encoding was found.
6
- class EncodingError < StandardError; end
7
- end
8
- end
@@ -1,71 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Mail #:nodoc:
4
- module Multibyte #:nodoc:
5
- # Holds data about a codepoint in the Unicode database
6
- class Codepoint
7
- attr_accessor :code, :combining_class, :decomp_type, :decomp_mapping, :uppercase_mapping, :lowercase_mapping
8
- end
9
-
10
- # Holds static data from the Unicode database
11
- class UnicodeDatabase
12
- ATTRIBUTES = :codepoints, :composition_exclusion, :composition_map, :boundary, :cp1252
13
-
14
- attr_writer(*ATTRIBUTES)
15
-
16
- def initialize
17
- @codepoints = Hash.new(Codepoint.new)
18
- @composition_exclusion = []
19
- @composition_map = {}
20
- @boundary = {}
21
- @cp1252 = {}
22
- end
23
-
24
- # Lazy load the Unicode database so it's only loaded when it's actually used
25
- ATTRIBUTES.each do |attr_name|
26
- class_eval(<<-EOS, __FILE__, __LINE__)
27
- def #{attr_name} # def codepoints
28
- load # load
29
- @#{attr_name} # @codepoints
30
- end # end
31
- EOS
32
- end
33
-
34
- # Loads the Unicode database and returns all the internal objects of UnicodeDatabase.
35
- def load
36
- begin
37
- @codepoints, @composition_exclusion, @composition_map, @boundary, @cp1252 = File.open(self.class.filename, 'rb') { |f| Marshal.load f.read }
38
- rescue Exception => e
39
- raise IOError.new("Couldn't load the Unicode tables for UTF8Handler (#{e.message}), ActiveSupport::Multibyte is unusable")
40
- end
41
-
42
- # Redefine the === method so we can write shorter rules for grapheme cluster breaks
43
- @boundary.each do |k,_|
44
- @boundary[k].instance_eval do
45
- def ===(other)
46
- detect { |i| i === other } ? true : false
47
- end
48
- end if @boundary[k].kind_of?(Array)
49
- end
50
-
51
- # define attr_reader methods for the instance variables
52
- class << self
53
- attr_reader(*ATTRIBUTES)
54
- end
55
- end
56
-
57
- # Returns the directory in which the data files are stored
58
- def self.dirname
59
- File.dirname(__FILE__) + '/../values/'
60
- end
61
-
62
- # Returns the filename for the data file for this version
63
- def self.filename
64
- File.expand_path File.join(dirname, "unicode_tables.dat")
65
- end
66
- end
67
-
68
- # UniCode Database
69
- UCD = UnicodeDatabase.new
70
- end
71
- end
@@ -1,88 +0,0 @@
1
- # encoding: utf-8
2
- # :nodoc:
3
- # OK... serious code smell in here... I just took the whole multibyte_chars code out of
4
- # ActiveSupport.... hacked it to fit... like a mallet bashing a square peg... the thing
5
- # fits in the hole... really!
6
- #
7
- # Bah... I'll get the first gem out and we'll fix this up.
8
- require File.join(File.dirname(__FILE__), 'multibyte')
9
-
10
- module Mail
11
-
12
- # Taken from Rails::Mail::Multibyte
13
- module Multibyte
14
-
15
- unless '1.9'.respond_to?(:force_encoding)
16
- # == Multibyte proxy
17
- #
18
- # +mb_chars+ is a multibyte safe proxy for string methods.
19
- #
20
- # In Ruby 1.8 and older it creates and returns an instance of the Mail::Multibyte::Chars class which
21
- # encapsulates the original string. A Unicode safe version of all the String methods are defined on this proxy
22
- # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsuled string.
23
- #
24
- # name = 'Claus Müller'
25
- # name.reverse #=> "rell??M sualC"
26
- # name.length #=> 13
27
- #
28
- # name.mb_chars.reverse.to_s #=> "rellüM sualC"
29
- # name.mb_chars.length #=> 12
30
- #
31
- # In Ruby 1.9 and newer +mb_chars+ returns +self+ because String is (mostly) encoding aware. This means that
32
- # it becomes easy to run one version of your code on multiple Ruby versions.
33
- #
34
- # == Method chaining
35
- #
36
- # All the methods on the Chars proxy which normally return a string will return a Chars object. This allows
37
- # method chaining on the result of any of these methods.
38
- #
39
- # name.mb_chars.reverse.length #=> 12
40
- #
41
- # == Interoperability and configuration
42
- #
43
- # The Chars object tries to be as interchangeable with String objects as possible: sorting and comparing between
44
- # String and Char work like expected. The bang! methods change the internal string representation in the Chars
45
- # object. Interoperability problems can be resolved easily with a +to_s+ call.
46
- #
47
- # For more information about the methods defined on the Chars proxy see Mail::Multibyte::Chars. For
48
- # information about how to change the default Multibyte behaviour see Mail::Multibyte.
49
- def mb_chars
50
- if Mail::Multibyte.proxy_class.wants?(self)
51
- Mail::Multibyte.proxy_class.new(self)
52
- else
53
- self
54
- end
55
- end
56
-
57
- # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have
58
- # them), returns false otherwise.
59
- def is_utf8?
60
- Mail::Multibyte::Chars.consumes?(self)
61
- end
62
-
63
- unless '1.8.7 and later'.respond_to?(:chars)
64
- def chars
65
- Mail::Deprecation.warn('String#chars has been deprecated in favor of String#mb_chars.', caller)
66
- mb_chars
67
- end
68
- end
69
-
70
- else
71
- def mb_chars #:nodoc
72
- self
73
- end
74
-
75
- def is_utf8? #:nodoc
76
- case encoding
77
- when Encoding::UTF_8
78
- valid_encoding?
79
- when Encoding::ASCII_8BIT, Encoding::US_ASCII
80
- dup.force_encoding(Encoding::UTF_8).valid_encoding?
81
- else
82
- false
83
- end
84
- end
85
- end
86
- end
87
-
88
- end