File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -20,12 +20,13 @@ def email_has_fields?(email, fields)
20
20
end
21
21
22
22
def visit_in_email ( email , link_text )
23
- visit ( parse_email_for_link ( email , link_text ) )
23
+ link = parse_email_for_link ( email , link_text )
24
+ visit URI . parse ( link ) . path
24
25
end
25
26
26
27
def click_first_link_in_email ( email )
27
28
link = links_in_email ( email ) . first
28
- visit link
29
+ visit URI . parse ( link ) . path
29
30
end
30
31
31
32
protected
@@ -64,13 +65,23 @@ def parse_email_for_explicit_link(email, regex)
64
65
65
66
# e.g. Click here in <a href="http://confirm">Click here</a>
66
67
def parse_email_for_anchor_text_link ( email , link_text )
67
- if match_data = email . body . match ( %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{ link_text } [^<]*?</a>} )
68
+ if email . multipart?
69
+ body = email . html_part . body
70
+ else
71
+ body = email . body
72
+ end
73
+ if match_data = body . match ( %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{ link_text } [^<]*?</a>} )
68
74
match_data [ 1 ]
69
75
end
70
76
end
71
77
72
78
def links_in_email ( email , protos = [ 'http' , 'https' ] )
73
- URI . extract ( email . body . to_s , protos )
79
+ if email . multipart?
80
+ body = email . html_part . body
81
+ else
82
+ body = email . body
83
+ end
84
+ URI . extract ( body . to_s , protos )
74
85
end
75
86
76
87
end
You can’t perform that action at this time.
0 commit comments