Do not fail in checking a condition on From/To/Cc

This should fix this error:
https://github.com/cantino/huginn/issues/745#issuecomment-176628911

Akinori MUSHA 8 gadi atpakaļ
vecāks
revīzija
91d76db975

+ 2 - 1
app/models/agents/imap_folder_agent.rb

@@ -227,7 +227,8 @@ module Agents
227 227
             }
228 228
           when 'from', 'to', 'cc'
229 229
             value.present? or next true
230
-            mail.header[key].addresses.any? { |address|
230
+            header = mail.header[key] or next false
231
+            header.addresses.any? { |address|
231 232
               Array(value).any? { |pattern|
232 233
                 glob_match?(pattern, address)
233 234
               }

+ 8 - 0
spec/models/agents/imap_folder_agent_spec.rb

@@ -183,6 +183,14 @@ describe Agents::ImapFolderAgent do
183 183
         expect { @checker.check }.not_to change { Event.count }
184 184
       end
185 185
 
186
+      it 'should not fail when a condition on Cc is given and a mail does not have the field' do
187
+        @checker.options['conditions']['cc'] = 'John.Doe@*'
188
+
189
+        expect {
190
+          expect { @checker.check }.not_to change { Event.count }
191
+        }.not_to raise_exception
192
+      end
193
+
186 194
       it 'should perform regexp matching and save named captures' do
187 195
         @checker.options['conditions'].update(
188 196
           'subject' => '\ARe: (?<a>.+)',