Class: TMail::Address

Inherits:
Object show all
Includes:
StrategyInterface, TextUtils
Defined in:
lib/tmail/obsolete.rb,
lib/tmail/address.rb

Overview

address.rb

Constant Summary

Constants included from TextUtils

TextUtils::ATOM_UNSAFE, TextUtils::CONTROL_CHAR, TextUtils::MESSAGE_ID, TextUtils::MIME_ENCODED, TextUtils::MONTH, TextUtils::NKF_FLAGS, TextUtils::PHRASE_UNSAFE, TextUtils::RFC2231_ENCODED, TextUtils::TOKEN_UNSAFE, TextUtils::WDAY, TextUtils::ZONESTR_TABLE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StrategyInterface

#accept_strategy, create_dest, #decoded, #encoded

Methods included from TextUtils

#atom_safe?, #decode_RFC2231, #decode_params, #join_domain, #message_id?, #mime_encoded?, #quote_atom, #quote_boundary, #quote_phrase, #quote_token, #time2str, #timezone_string_to_unixtime, #to_kcode, #token_safe?, #unquote

Constructor Details

#initialize(local, domain) ⇒ Address

Returns a new instance of Address.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tmail/address.rb', line 51

def initialize( local, domain )
  if domain
    domain.each do |s|
      raise SyntaxError, 'empty word in domain' if s.empty?
    end
  end

  @local = local
  @domain = domain
  @name   = nil
  @routes = []
end

Instance Attribute Details

#nameObject Also known as: phrase

Returns the value of attribute name.



64
65
66
# File 'lib/tmail/address.rb', line 64

def name
  @name
end

#routesObject (readonly) Also known as: route

Returns the value of attribute routes.



74
75
76
# File 'lib/tmail/address.rb', line 74

def routes
  @routes
end

Class Method Details

.parse(str) ⇒ Object



43
44
45
# File 'lib/tmail/address.rb', line 43

def Address.parse( str )
  Parser.parse :ADDRESS, str
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



103
104
105
# File 'lib/tmail/address.rb', line 103

def ==( other )
  other.respond_to? :spec and self.spec == other.spec
end

#accept(strategy, dummy1 = nil, dummy2 = nil) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/tmail/address.rb', line 122

def accept( strategy, dummy1 = nil, dummy2 = nil )
  unless @local
    strategy.meta '<>'   # empty return-path
    return
  end

  spec_p = (not @name and @routes.empty?)
  if @name
    strategy.phrase @name
    strategy.space
  end
  tmp = spec_p ? '' : '<'
  unless @routes.empty?
    tmp << @routes.map {|i| '@' + i }.join(',') << ':'
  end
  tmp << self.spec
  tmp << '>' unless spec_p
  strategy.meta tmp
  strategy.lwsp ''
end

#address_group?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/tmail/address.rb', line 47

def address_group?
  false
end

#domainObject



86
87
88
89
# File 'lib/tmail/address.rb', line 86

def domain
  return nil unless @domain
  join_domain(@domain)
end

#dupObject



113
114
115
116
117
118
# File 'lib/tmail/address.rb', line 113

def dup
  obj = self.class.new(@local.dup, @domain.dup)
  obj.name = @name.dup if @name
  obj.routes.replace @routes
  obj
end

#hashObject



109
110
111
# File 'lib/tmail/address.rb', line 109

def hash
  @local.hash ^ @domain.hash
end

#inspectObject



76
77
78
# File 'lib/tmail/address.rb', line 76

def inspect
  "#<#{self.class} #{address()}>"
end

#localObject



80
81
82
83
84
# File 'lib/tmail/address.rb', line 80

def local
  return nil unless @local
  return '""' if @local.size == 1 and @local[0].empty?
  @local.map {|i| quote_atom(i) }.join('.')
end

#specObject Also known as: address, addr



91
92
93
94
95
96
97
98
99
# File 'lib/tmail/address.rb', line 91

def spec
  s = self.local
  d = self.domain
  if s and d
    s + '@' + d
  else
    s
  end
end

#spec=(str) ⇒ Object Also known as: addr=, address=



92
93
94
# File 'lib/tmail/obsolete.rb', line 92

def spec=( str )
  @local, @domain = str.split(/@/,2).map {|s| s.split(/\./) }
end