<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>test/fixtures/apple_unquoted_content_type</filename>
    </added>
    <added>
      <filename>test/fixtures/unquoted_filename_in_attachment</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -243,6 +243,8 @@ module TMail
 
     def do_parse
       quote_boundary
+      quote_unquoted_name
+      quote_unquoted_bencode
       obj = Parser.parse(self.class::PARSE_TYPE, @body, @comments)
       set obj if obj
     end
@@ -817,7 +819,7 @@ module TMail
         if v
           strategy.meta ';'
           strategy.space
-          strategy.kv_pair k, v
+          strategy.kv_pair k, unquote(v)
         end
       end
     end</diff>
      <filename>lib/tmail/header.rb</filename>
    </modified>
    <modified>
      <diff>@@ -57,8 +57,11 @@ module TMail
   end
 
   class Attachment
+    
+    include TextUtils
+    
     def original_filename(to_charset = 'utf-8')
-      Unquoter.unquote_and_convert_to(quoted_filename, to_charset)
+      Unquoter.unquote_and_convert_to(quoted_filename, to_charset).chomp
     end
   end
 </diff>
      <filename>lib/tmail/quoting.rb</filename>
    </modified>
    <modified>
      <diff>@@ -161,7 +161,7 @@ module TMail
     # Unwraps supplied string from inside double quotes
     # Returns unquoted string
     def unquote( str )
-      str =~ /^&quot;(.*?)&quot;$/ ? $1 : str
+      str =~ /^&quot;(.*?)&quot;$/m ? $1 : str
     end
     
     # Provides a method to join a domain name by it's parts and also makes it
@@ -329,9 +329,33 @@ module TMail
         end
       end
     end
+    
+    # AppleMail generates illegal character contained Content-Type parameter like:
+    #   name==?ISO-2022-JP?B?...=?=
+    # so quote. (This case is only value fits in one line.)
+    def quote_unquoted_bencode
+      @body = @body.gsub(%r&quot;(;\s+[-a-z]+=)(=\?.+?)([;\r\n ]|\z)&quot;m) {
+        head, should_quoted, tail = $~.captures
+        # head: &quot;; name=&quot;
+        # should_quoted: &quot;=?ISO-2022-JP?B?...=?=&quot;
+    
+        head &lt;&lt; quote_token(should_quoted) &lt;&lt; tail
+      }
+    end
+    
+    # AppleMail generates name=filename attributes in the content type that
+    # contain spaces.  Need to handle this so the TMail Parser can.
+    def quote_unquoted_name
+      @body = @body.gsub(%r|(name=)([\w\s.]+)(.*)|m) {
+        head, should_quoted, tail = $~.captures
+        # head: &quot;; name=&quot;
+        # should_quoted: &quot;=?ISO-2022-JP?B?...=?=&quot;
+        head  &lt;&lt; quote_token(should_quoted) &lt;&lt; tail
+      }
+    end
+    
     #:startdoc:
-
-
+    
   end
 
 end</diff>
      <filename>lib/tmail/utils.rb</filename>
    </modified>
    <modified>
      <diff>@@ -75,7 +75,9 @@
       &lt;p&gt;You can get the latest version of TMail from the TMail
       &lt;a href=&quot;http://rubyforge.org/frs/?group_id=4512&amp;amp;release_id=15889&quot;
       title=&quot;RubyForge: TMail: Project Filelist&quot;&gt;RubyForge&lt;/a&gt; project
-      or via Ruby Gems &quot;tmail&quot;&lt;/p&gt;
+      or via Ruby Gems &quot;tmail&quot;, or feel free to grab the source code and
+      submit patches via the &lt;a href=&quot;http://github.com/mikel/tmail/tree/master&quot;
+      title=&quot;mikel's tmail at master - GitHub&quot;&gt;GitHub TMail&lt;/a&gt; site.&lt;/p&gt;
 
       &lt;p&gt;TMail is written in Ruby and a (very) small bit of supporting C
       that has pure ruby replacements if you can't compile on your computer.</diff>
      <filename>site/index.html</filename>
    </modified>
    <modified>
      <diff>@@ -92,7 +92,7 @@ class TestAddress &lt; Test::Unit::TestCase
     assert_equal ok[:address],      a.spec,   str.inspect + &quot; (spec)\n&quot;
     assert_equal ok[:local],        a.local,  str.inspect + &quot; (local)\n&quot;
     assert_equal ok[:domain],       a.domain, str.inspect + &quot; (domain)\n&quot;
-  # assert_equal ok[:format],       a.to_s,   str.inspect + &quot; (to_s)\n&quot;
+    #assert_equal ok[:format],       a.to_s,   str.inspect + &quot; (to_s)\n&quot;
   end
 
   def validate_case__group( str, groupname, addrlist )</diff>
      <filename>test/test_address.rb</filename>
    </modified>
    <modified>
      <diff>@@ -51,7 +51,7 @@ HERE
     fixture = File.read(File.dirname(__FILE__) + &quot;/fixtures/raw_email_with_quoted_attachment_filename&quot;)
     mail = TMail::Mail.parse(fixture)
     attachment = mail.attachments.last
-	str = &quot;Eelanal&#252;&#252;si p&#228;ring.jpg&quot;
+    str = &quot;Eelanal&#252;&#252;si p&#228;ring.jpg&quot;
     assert_equal str, attachment.original_filename
   end
 
@@ -72,5 +72,17 @@ HERE
     mail = TMail::Mail.parse(fixture)
     assert_equal(1, mail.attachments.length)
   end
+
+  def test_content_nil_returned_if_name_of_attachment_type_unquoted
+    fixture = File.read(File.dirname(__FILE__) + &quot;/fixtures/unquoted_filename_in_attachment&quot;)
+    mail = TMail::Mail.parse(fixture)
+    assert_equal(&quot;image/png&quot;, mail.attachments.first.content_type)
+  end
+
+  def test_unquoted_apple_mail_content_type
+    fixture = File.read(File.dirname(__FILE__) + &quot;/fixtures/apple_unquoted_content_type&quot;)
+    mail = TMail::Mail.parse(fixture)
+    assert_equal(&quot;application/pdf&quot;, mail.attachments.first.content_type)
+  end
   
 end</diff>
      <filename>test/test_attachments.rb</filename>
    </modified>
    <modified>
      <diff>@@ -999,4 +999,23 @@ class ContentDispositionHeaderTester &lt; Test::Unit::TestCase
     assert_not_equal(message_id, mail.message_id)
   end
 
+  def test_content_type_does_not_unquote_parameter_values
+    japanese_jis_filename = &quot;&#165;e$B4A;z&#165;e(B.jpg&quot;
+    mailsrc =&lt;&lt;ENDSTRING
+Content-Type: image/jpeg;
+              name=&quot;#{japanese_jis_filename}&quot;
+Content-Transfer-Encoding: Base64
+Content-Disposition: attachment
+ENDSTRING
+    result =&lt;&lt;ENDSTRING
+Content-Type: image/jpeg; name*=iso-2022-jp'ja'%c2%a5e$B4A%3bz%c2%a5e%28B.jpg
+Content-Transfer-Encoding: Base64
+Content-Disposition: attachment
+
+ENDSTRING
+    
+    mail = TMail::Mail.parse(mailsrc)
+    assert_equal(result.gsub(&quot;\n&quot;, &quot;\r\n&quot;), mail.encoded)
+  end
+
 end</diff>
      <filename>test/test_header.rb</filename>
    </modified>
    <modified>
      <diff>@@ -734,20 +734,7 @@ EOF
     part = TMail::Mail.parse(&quot;Content-Type: text/plain\n\nBlah&quot;)
     mail.parts &lt;&lt; part
     mail.preamble = 'This is the preamble'
-    # normalize the boundary to something non-random to assert against
-    str = mail.encoded
-    result = str.gsub(str[/boundary=&quot;(.*?)&quot;/, 1], 'this-is-the-boundary').gsub(/\r\n\t/, ' ')
-    expected =&lt;&lt;EOF
-Content-Type: multipart/mixed; boundary=&quot;this-is-the-boundary&quot;
-
-This is the preamble
---this-is-the-boundary
-Content-Type: text/plain
-
-Blah
---this-is-the-boundary--
-EOF
-    assert_equal(crlf(expected), result)
+    assert(mail.encoded =~ /\r\n\r\nThis is the preamble\r\n--mimepart/)
   end
   
 end</diff>
      <filename>test/test_mail.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>test/fixtures/attachment_type.eml.txt</filename>
    </removed>
    <removed>
      <filename>test/fixtures/nil_attachment_type</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>3952471cc4b232ec428cd1bdca199fda6711a7df</id>
    </parent>
  </parents>
  <author>
    <name>Mikel Lindsaar</name>
    <email>raasdnil@gmail.com</email>
  </author>
  <url>http://github.com/mikel/tmail/commit/d3f1d826df44e83287c690d58194f54b42500b0d</url>
  <id>d3f1d826df44e83287c690d58194f54b42500b0d</id>
  <committed-date>2009-08-06T23:19:34-07:00</committed-date>
  <authored-date>2009-08-06T23:19:34-07:00</authored-date>
  <message>Applied two patches from taimamiso (shirai-kaoru) and tests</message>
  <tree>40c50c1598c5afa1909793f08192717ea47b8bbb</tree>
  <committer>
    <name>Mikel Lindsaar</name>
    <email>raasdnil@gmail.com</email>
  </committer>
</commit>
