13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/dm-imap-adapter/types.rb', line 13
def self.typecast(value, property)
if value.nil? || value.empty?
[]
else
if value.is_a?(Array) && value.first.is_a?(Net::IMAP::Address)
value
else
value = [value].flatten
value.map do |val|
if val =~ /<.*>$/
matches = val.match(/(.*)<(.*)@(.*)>/)
if matches
n = Net::IMAP::Address.new
n.name = matches[0].strip
n.mailbox = matches[1].strip
n.host = matches[2].strip
n
else
nil
end else
matches = val.split "@"
if matches
n = Net::IMAP::Address.new
n.mailbox = matches[0].strip
n.host = matches[1].strip
n
else
nil
end end
end.compact end endend
|