3 = Address handling class
8 # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
18 # The above copyright notice and this permission notice shall be
19 # included in all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
30 # with permission of Minero Aoki.
33 require 'tmail/encode'
34 require 'tmail/parser'
43 def Address.parse( str )
44 Parser.parse :ADDRESS, str
51 def initialize( local, domain )
54 raise SyntaxError, 'empty word in domain' if s.empty?
68 @name = nil if str and str.empty?
77 "#<#{self.class} #{address()}>"
81 return nil unless @local
82 return '""' if @local.size == 1 and @local[0].empty?
83 @local.map {|i| quote_atom(i) }.join('.')
87 return nil unless @domain
104 other.respond_to? :spec and self.spec == other.spec
110 @local.hash ^ @domain.hash
114 obj = self.class.new(@local.dup, @domain.dup)
115 obj.name = @name.dup if @name
116 obj.routes.replace @routes
120 include StrategyInterface
122 def accept( strategy, dummy1 = nil, dummy2 = nil )
124 strategy.meta '<>' # empty return-path
128 spec_p = (not @name and @routes.empty?)
130 strategy.phrase @name
133 tmp = spec_p ? '' : '<'
134 unless @routes.empty?
135 tmp << @routes.map {|i| '@' + i }.join(',') << ':'
138 tmp << '>' unless spec_p
154 def initialize( name, addrs )
162 other.respond_to? :to_a and @addresses == other.to_a
168 map {|i| i.hash }.hash
184 @addresses.each(&block)
194 @addresses.include? a
199 @addresses.each do |a|
200 if a.respond_to? :flatten
209 def each_address( &block )
223 include StrategyInterface
225 def accept( strategy, dummy1 = nil, dummy2 = nil )
226 strategy.phrase @name