valodzka-tmail 1.2.3.2 → 1.2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tmail/encode.rb +5 -4
- data/lib/tmail/mail.rb +10 -1
- data/test/test_address.rb +8 -3
- data/test/test_attachments.rb +4 -1
- data/test/test_header.rb +2 -2
- data/test/test_mail.rb +7 -0
- metadata +1 -1
data/lib/tmail/encode.rb
CHANGED
@@ -348,21 +348,22 @@ module TMail
|
|
348
348
|
def scanadd( str, force = false )
|
349
349
|
types = ''
|
350
350
|
strs = []
|
351
|
-
|
351
|
+
has_encoding = str.respond_to?(:encoding)
|
352
|
+
if has_encoding
|
352
353
|
enc = str.encoding
|
353
354
|
str.force_encoding(Encoding::ASCII_8BIT)
|
354
355
|
end
|
355
356
|
until str.empty?
|
356
357
|
if m = /\A[^\e\t\r\n ]+/.match(str)
|
357
358
|
types << (force ? 'j' : 'a')
|
358
|
-
if
|
359
|
+
if has_encoding
|
359
360
|
strs.push m[0].force_encoding(enc)
|
360
361
|
else
|
361
362
|
strs.push m[0]
|
362
363
|
end
|
363
364
|
elsif m = /\A[\t\r\n ]+/.match(str)
|
364
365
|
types << 's'
|
365
|
-
if
|
366
|
+
if has_encoding
|
366
367
|
strs.push m[0].force_encoding(enc)
|
367
368
|
else
|
368
369
|
strs.push m[0]
|
@@ -373,7 +374,7 @@ module TMail
|
|
373
374
|
str = m.post_match
|
374
375
|
if esc != "\e(B" and m = /\A[^\e]+/.match(str)
|
375
376
|
types << 'j'
|
376
|
-
if
|
377
|
+
if has_encoding
|
377
378
|
strs.push m[0].force_encoding(enc)
|
378
379
|
else
|
379
380
|
strs.push m[0]
|
data/lib/tmail/mail.rb
CHANGED
@@ -414,6 +414,12 @@ module TMail
|
|
414
414
|
|
415
415
|
when /^charset=.*/
|
416
416
|
|
417
|
+
when /\A<html/i
|
418
|
+
# simple heuristic for bad formed mails
|
419
|
+
# - look like content start immediately after header
|
420
|
+
# without double new line
|
421
|
+
f.seek -line.size, IO::SEEK_CUR # not universal, but better then nothing
|
422
|
+
break
|
417
423
|
else
|
418
424
|
raise SyntaxError, "wrong mail header: '#{line.inspect}'"
|
419
425
|
end
|
@@ -535,7 +541,10 @@ module TMail
|
|
535
541
|
|
536
542
|
def skip_header( f )
|
537
543
|
while line = f.gets
|
538
|
-
|
544
|
+
if /(\A[\r\n]*\z)|(\A<html)/ === line
|
545
|
+
f.seek -line.size, IO::SEEK_CUR if $2
|
546
|
+
return
|
547
|
+
end
|
539
548
|
end
|
540
549
|
end
|
541
550
|
|
data/test/test_address.rb
CHANGED
@@ -170,11 +170,16 @@ class TestAddress < Test::Unit::TestCase
|
|
170
170
|
# "\223\372\226{\214\352"
|
171
171
|
# "\e$BF|K\\8l\e(B"
|
172
172
|
# GyRCRnxLXDhsGyhC
|
173
|
+
force = if "".respond_to? :force_encoding
|
174
|
+
proc{|x,e| x.force_encoding e }
|
175
|
+
else
|
176
|
+
proc{|x,e| x }
|
177
|
+
end
|
173
178
|
|
174
179
|
TMail.KCODE = 'NONE'
|
175
180
|
validate_case__address\
|
176
181
|
'=?iso-2022-jp?B?GyRCRnxLXDhsGyhC?= <aamine@loveruby.net>',
|
177
|
-
:display_name => "\e$BF|K\\8l\e(B",
|
182
|
+
:display_name => force["\e$BF|K\\8l\e(B", "ISO-2022-JP"],
|
178
183
|
:address => 'aamine@loveruby.net',
|
179
184
|
:local => 'aamine',
|
180
185
|
:domain => 'loveruby.net',
|
@@ -182,7 +187,7 @@ class TestAddress < Test::Unit::TestCase
|
|
182
187
|
|
183
188
|
validate_case__address\
|
184
189
|
'=?iso-2022-jp?Q?=1b=24=42=46=7c=4b=5c=38=6c=1b=28=42?= <aamine@loveruby.net>',
|
185
|
-
:display_name => "\e$BF|K\\8l\e(B",
|
190
|
+
:display_name => force["\e$BF|K\\8l\e(B", "iso-2022-jp"],
|
186
191
|
:address => 'aamine@loveruby.net',
|
187
192
|
:local => 'aamine',
|
188
193
|
:domain => 'loveruby.net',
|
@@ -209,7 +214,7 @@ class TestAddress < Test::Unit::TestCase
|
|
209
214
|
|
210
215
|
TMail.KCODE = 'SJIS'
|
211
216
|
expected = "\223\372\226{\214\352"
|
212
|
-
expected.force_encoding('
|
217
|
+
expected.force_encoding('SJIS') if expected.respond_to? :force_encoding
|
213
218
|
validate_case__address\
|
214
219
|
'=?iso-2022-jp?B?GyRCRnxLXDhsGyhC?= <aamine@loveruby.net>',
|
215
220
|
:display_name => expected,
|
data/test/test_attachments.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'test_helper'
|
2
3
|
require 'tmail'
|
3
4
|
|
@@ -42,7 +43,9 @@ HERE
|
|
42
43
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
|
43
44
|
mail = TMail::Mail.parse(fixture)
|
44
45
|
attachment = mail.attachments.last
|
45
|
-
|
46
|
+
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
|
47
|
+
expected.force_encoding "BINARY" if expected.respond_to? :force_encoding
|
48
|
+
assert_equal expected, attachment.original_filename
|
46
49
|
end
|
47
50
|
|
48
51
|
def test_attachment_with_quoted_filename
|
data/test/test_header.rb
CHANGED
@@ -881,7 +881,7 @@ class ContentDispositionHeaderTester < Test::Unit::TestCase
|
|
881
881
|
assert_equal 'attachment', h.disposition
|
882
882
|
assert_equal 1, h.params.size
|
883
883
|
expected = "\223\372\226{\214\352.doc"
|
884
|
-
expected.force_encoding
|
884
|
+
expected.force_encoding('Windows-31J').encode!("Shift_JIS") if expected.respond_to? :force_encoding
|
885
885
|
assert_equal expected, h.params['filename']
|
886
886
|
|
887
887
|
# raw SJIS string in value (quoted-string)
|
@@ -909,7 +909,7 @@ class ContentDispositionHeaderTester < Test::Unit::TestCase
|
|
909
909
|
assert_equal 'attachment', h.disposition
|
910
910
|
assert_equal 1, h.params.size
|
911
911
|
expected = "\223\372\226{\214\352.doc"
|
912
|
-
expected.force_encoding
|
912
|
+
expected.force_encoding('Windows-31J').encode!("Shift_JIS") if expected.respond_to? :force_encoding
|
913
913
|
assert_equal expected, h.params['filename']
|
914
914
|
end
|
915
915
|
|
data/test/test_mail.rb
CHANGED
@@ -757,5 +757,12 @@ EOF
|
|
757
757
|
end
|
758
758
|
end
|
759
759
|
|
760
|
+
def test_html_body_start
|
761
|
+
assert_nothing_raised do
|
762
|
+
tmail = TMail::Mail.load("#{File.dirname(__FILE__)}/fixtures/raw_email_with_bad_body_start")
|
763
|
+
assert_equal 1, tmail.parts.size
|
764
|
+
assert_match /\A<html/, tmail.parts.first.body
|
765
|
+
end
|
766
|
+
end
|
760
767
|
|
761
768
|
end
|