5 # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be
16 # included in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
27 # with permission of Minero Aoki.
30 require 'tmail/encode'
31 require 'tmail/parser'
40 def Address.parse( str )
41 Parser.parse :ADDRESS, str
48 def initialize( local, domain )
51 raise SyntaxError, 'empty word in domain' if s.empty?
64 @name = nil if str and str.empty?
73 "#<#{self.class} #{address()}>"
77 return nil unless @local
78 return '""' if @local.size == 1 and @local[0].empty?
79 @local.map {|i| quote_atom(i) }.join('.')
83 return nil unless @domain
101 other.respond_to? :spec and self.spec == other.spec
107 @local.hash ^ @domain.hash
111 obj = self.class.new(@local.dup, @domain.dup)
112 obj.name = @name.dup if @name
113 obj.routes.replace @routes
117 include StrategyInterface
119 def accept( strategy, dummy1 = nil, dummy2 = nil )
121 strategy.meta '<>' # empty return-path
125 spec_p = (not @name and @routes.empty?)
127 strategy.phrase @name
130 tmp = spec_p ? '' : '<'
131 unless @routes.empty?
132 tmp << @routes.map {|i| '@' + i }.join(',') << ':'
135 tmp << '>' unless spec_p
151 def initialize( name, addrs )
159 other.respond_to? :to_a and @addresses == other.to_a
165 map {|i| i.hash }.hash
181 @addresses.each(&block)
191 @addresses.include? a
196 @addresses.each do |a|
197 if a.respond_to? :flatten
206 def each_address( &block )
220 include StrategyInterface
222 def accept( strategy, dummy1 = nil, dummy2 = nil )
223 strategy.phrase @name