attachments 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -2,6 +2,7 @@ require 'rubygems'
2
2
  require 'uuidtools'
3
3
  require 'fileutils'
4
4
  require 'mail'
5
+ require 'iconv'
5
6
 
6
7
 
7
8
  module Attachments
@@ -76,7 +77,7 @@ module Attachments
76
77
 
77
78
  def parse_part mail
78
79
  # Filter parts with a type that is not of interest
79
- ct = mail.content_type.split(/;/, 2)[0] if mail.content_type
80
+ ct, charset = mail.content_type.split(/;/, 2) if mail.content_type
80
81
  unless(mail.multipart? || (ct && @include_types.include?(ct)))
81
82
  return
82
83
  end
@@ -105,7 +106,13 @@ module Attachments
105
106
  m.encode("utf-8")
106
107
  rescue
107
108
  # Ruby 1.8 doesn't know encode
108
- m
109
+ if charset && charset.match(/charset=/i)
110
+ charset.gsub!(/charset=/i, "")
111
+ charset.strip!
112
+ Iconv.conv("utf-8", charset, m)
113
+ else
114
+ m
115
+ end
109
116
  end
110
117
  else
111
118
  mail.body.decoded
@@ -1,4 +1,5 @@
1
1
  require 'helper'
2
+ require 'iconv'
2
3
 
3
4
  class TestAttachments < Test::Unit::TestCase
4
5
  def setup
@@ -30,4 +31,14 @@ class TestAttachments < Test::Unit::TestCase
30
31
  @extract.close
31
32
  assert !File::exists?(tmpfile)
32
33
  end
34
+
35
+
36
+ should "save as text/plain as utf-8" do
37
+ tmpfile = @extract.files[0][:tmpfile]
38
+ m = File.read(tmpfile)
39
+ assert_nothing_raised do
40
+ # Provoke an exception if not valid utf-8
41
+ Iconv.conv("ISO-8859-1", "utf-8", m)
42
+ end
43
+ end
33
44
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attachments
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rune Myrland