2012-05-04 11:33:05 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class EmailParserTest < ActiveSupport::TestCase
|
|
|
|
test 'parse' do
|
|
|
|
files = [
|
|
|
|
{
|
|
|
|
:data => IO.read('test/fixtures/mail1.box'),
|
|
|
|
:body_md5 => 'fb6ed5070ffbb821b67b15b83239e1db',
|
|
|
|
:params => {
|
|
|
|
:from => 'John.Smith@example.com',
|
|
|
|
:from_email => 'John.Smith@example.com',
|
|
|
|
:from_display_name => nil,
|
|
|
|
:subject => 'CI Daten für PublicView ',
|
|
|
|
},
|
|
|
|
},
|
2012-05-04 19:30:22 +00:00
|
|
|
{
|
|
|
|
:data => IO.read('test/fixtures/mail2.box'),
|
|
|
|
:body_md5 => '25a1ff722497271965b55e52659784a6',
|
|
|
|
:params => {
|
|
|
|
:from => 'Martin Edenhofer <martin@example.com>',
|
|
|
|
:from_email => 'martin@example.com',
|
|
|
|
:from_display_name => 'Martin Edenhofer',
|
|
|
|
:subject => 'aaäöüßad asd',
|
|
|
|
:plain_part => "äöüß ad asd\r\n\r\n-Martin\r\n\r\n--\r\nOld programmers never die. They just branch to a new address.",
|
|
|
|
},
|
|
|
|
},
|
2012-05-05 09:24:05 +00:00
|
|
|
{
|
|
|
|
:data => IO.read('test/fixtures/mail3.box'),
|
|
|
|
:body_md5 => '0914848466334919eb33ad4de79d6189',
|
|
|
|
:params => {
|
|
|
|
:from => '"Günther John | Example GmbH" <k.guenther@example.com>',
|
|
|
|
:from_email => 'k.guenther@example.com',
|
|
|
|
:from_display_name => 'Günther John | Example GmbH',
|
|
|
|
:subject => 'Ticket Templates',
|
|
|
|
},
|
|
|
|
},
|
2012-05-04 11:33:05 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
files.each { |file|
|
|
|
|
|
|
|
|
parser = Channel::EmailParser.new
|
|
|
|
data = parser.parse( file[:data] )
|
|
|
|
|
2012-05-04 19:30:22 +00:00
|
|
|
# check body
|
2012-05-04 11:33:05 +00:00
|
|
|
md5 = Digest::MD5.hexdigest( data[:plain_part] )
|
2012-05-04 19:30:22 +00:00
|
|
|
assert_equal( file[:body_md5], md5 )
|
2012-05-06 20:48:23 +00:00
|
|
|
|
2012-05-04 19:30:22 +00:00
|
|
|
# check params
|
2012-05-04 11:33:05 +00:00
|
|
|
file[:params].each { |key, value|
|
2012-05-04 19:30:22 +00:00
|
|
|
if key.to_s == 'plain_part'
|
|
|
|
assert_equal( Digest::MD5.hexdigest( file[:params][key.to_sym].to_s ), Digest::MD5.hexdigest( data[key.to_sym].to_s ) )
|
|
|
|
else
|
|
|
|
assert_equal( file[:params][key.to_sym], data[key.to_sym] )
|
|
|
|
end
|
2012-05-04 11:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|