blob: 4603b695f8170508d2f0206fa44b01c1e3793fca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '../../../spec_helper')
describe 'when creating a mail object from raw data' do
it 'should correctly parse a multipart email with a linebreak in the boundary' do
mail = get_fixture_mail('space-boundary.email')
mail.parts.size.should == 2
mail.multipart?.should == true
end
it 'should parse multiple to addresses with unqoted display names' do
mail = get_fixture_mail('multiple-unquoted-display-names.email')
mail.to.should == ["request-66666-caa77777@whatdotheyknow.com", "foi@example.com"]
end
it 'should convert an iso8859 email to utf8' do
mail = get_fixture_mail('iso8859_2_raw_email.email')
mail.subject.should have_text(/gjatë/u)
MailHandler.get_part_body(mail).is_utf8?.should == true
end
end
describe 'when asked for the from name' do
it 'should return nil if there is a blank "From" field' do
mail_data = load_file_fixture('incoming-request-plain.email')
mail_data.gsub!('EMAIL_FROM', '')
mail = MailHandler.mail_from_raw_email(mail_data)
MailHandler.get_from_name(mail).should == nil
end
it 'should correctly return an encoded name from the from field' do
mail = get_fixture_mail('quoted-subject-iso8859-1.email')
MailHandler.get_from_name(mail).should == 'Coordenação de Relacionamento, Pesquisa e Informação/CEDI'
end
it 'should get a name from a "From" field with a name and address' do
mail = get_fixture_mail('incoming-request-oft-attachments.email')
MailHandler.get_from_name(mail).should == 'Public Authority'
end
it 'should return nil from a "From" field that is just a name'do
mail = get_fixture_mail('track-response-webshield-bounce.email')
MailHandler.get_from_name(mail).should == nil
end
end
describe 'when asked for the from address' do
it 'should return nil if there is a blank "From" field' do
mail_data = load_file_fixture('incoming-request-plain.email')
mail_data.gsub!('EMAIL_FROM', '')
mail = MailHandler.mail_from_raw_email(mail_data)
MailHandler.get_from_address(mail).should == nil
end
it 'should correctly return an address from a mail that has an encoded name in the from field' do
mail = get_fixture_mail('quoted-subject-iso8859-1.email')
MailHandler.get_from_address(mail).should == 'geraldinequango@localhost'
end
it 'should return nil if there is no address in the "From" field' do
mail = get_fixture_mail('track-response-webshield-bounce.email')
MailHandler.get_from_address(mail).should == nil
end
it 'should return the "From" email address if there is one' do
mail = get_fixture_mail('track-response-abcmail-oof.email')
MailHandler.get_from_address(mail).should == 'Name.Removed@example.gov.uk'
end
it 'should get an address from a "From" field with a name and address' do
mail = get_fixture_mail('incoming-request-oft-attachments.email')
MailHandler.get_from_address(mail).should == 'public@authority.gov.uk'
end
end
describe 'when asked for all the addresses a mail has been sent to' do
it 'should return an array containing the envelope-to address and the to address, and the cc address if there is one' do
mail_data = load_file_fixture('humberside-police-odd-mime-type.email')
mail_data.gsub!('Envelope-to: request-5335-xxxxxxxx@whatdotheyknow.com',
'Envelope-to: request-5555-xxxxxxxx@whatdotheyknow.com')
mail_data.gsub!('Cc: request-5335-xxxxxxxx@whatdotheyknow.com',
'Cc: request-3333-xxxxxxxx@whatdotheyknow.com')
mail = MailHandler.mail_from_raw_email(mail_data)
MailHandler.get_all_addresses(mail).should == ['request-5335-xxxxxxxx@whatdotheyknow.com',
'request-3333-xxxxxxxx@whatdotheyknow.com',
'request-5555-xxxxxxxx@whatdotheyknow.com']
end
it 'should only return unique values' do
# envelope-to and to fields are the same
mail = get_fixture_mail('humberside-police-odd-mime-type.email')
MailHandler.get_all_addresses(mail).should == ['request-5335-xxxxxxxx@whatdotheyknow.com']
end
it 'should handle the absence of an envelope-to or cc field' do
mail_data = load_file_fixture('autoresponse-header.email')
mail_data.gsub!('To: FOI Person <EMAIL_TO>',
'To: FOI Person <request-5555-xxxxxxxx@whatdotheyknow.com>')
mail = MailHandler.mail_from_raw_email(mail_data)
MailHandler.get_all_addresses(mail).should == ["request-5555-xxxxxxxx@whatdotheyknow.com"]
end
end
|