Skip to content
This repository
Browse code

Made the unquoted subject and body the default

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@964 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit cb69736a1084d5412ede7628f864eccc356bb88c 1 parent 553f115
David Heinemeier Hansson authored March 21, 2005
4  actionmailer/README
@@ -66,13 +66,13 @@ Example:
66 66
     def receive(email)
67 67
       page = Page.find_by_address(email.to.first)
68 68
       page.emails.create(
69  
-        :subject => email.unquoted_subject, :body => email.unquoted_body_with_all_parts
  69
+        :subject => email.subject, :body => email.body
70 70
       )
71 71
 
72 72
       if email.has_attachments?
73 73
         for attachment in email.attachments
74 74
           page.attachments.create({ 
75  
-            :file => attachment, :description => email.unquoted_subject
  75
+            :file => attachment, :description => email.subject
76 76
           })
77 77
         end
78 78
       end
1  actionmailer/lib/action_mailer/vendor/tmail/facade.rb
@@ -261,6 +261,7 @@ def subject( default = nil )
261 261
         default
262 262
       end
263 263
     end
  264
+    alias quoted_subject subject
264 265
 
265 266
     def subject=( str )
266 267
       set_string_attr 'Subject', str
2  actionmailer/lib/action_mailer/vendor/tmail/mail.rb
@@ -322,7 +322,7 @@ def each( &block )
322 322
       body_port().ropen {|f| f.each(&block) }
323 323
     end
324 324
 
325  
-    def body
  325
+    def quoted_body
326 326
       parse_body
327 327
       @body_port.ropen {|f|
328 328
           return f.read
13  actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
@@ -3,24 +3,25 @@
3 3
 
4 4
 module TMail
5 5
   class Mail
6  
-    def unquoted_subject(to_charset = 'utf-8')
7  
-      Unquoter.unquote_and_convert_to(subject || "", to_charset)
  6
+    def subject(to_charset = 'utf-8')
  7
+      Unquoter.unquote_and_convert_to(quoted_subject || "", to_charset)
8 8
     end
9 9
 
10 10
     def unquoted_body(to_charset = 'utf-8')
11  
-      Unquoter.unquote_and_convert_to(body || "", to_charset, header["content-type"]["charset"])
  11
+      Unquoter.unquote_and_convert_to(quoted_body || "", to_charset, header["content-type"]["charset"])
12 12
     end
13 13
 
14  
-    def unquoted_body_with_all_parts(to_charset = 'utf-9', &block)
  14
+    def body(to_charset = 'utf-8', &block)
15 15
       attachment_presenter = block || Proc.new { |file_name| "Attachment: #{file_name}\n" }
16 16
       
17 17
       if multipart?
18 18
         parts.collect { |part| 
19 19
           part.header["content-type"].main_type == "text" ? 
20  
-            part.unquoted_body : attachment_presenter.call(part.header["content-type"].params["name"])
  20
+            part.unquoted_body(to_charset) :
  21
+            attachment_presenter.call(part.header["content-type"].params["name"])
21 22
         }.join
22 23
       else
23  
-        unquoted_body
  24
+        unquoted_body(to_charset)
24 25
       end
25 26
     end
26 27
   end
16  actionmailer/test/mail_service_test.rb
@@ -212,5 +212,21 @@ def test_perform_deliveries_flag
212 212
     assert_equal 1, ActionMailer::Base.deliveries.size
213 213
   end
214 214
 
  215
+  def test_unquote_subject
  216
+    msg = <<EOF
  217
+From: me@example.com
  218
+Subject: =?utf-8?Q?testing_testing_=D6=A4?=
  219
+Content-Type: text/plain; charset=iso-8859-1
  220
+
  221
+This_is_a_test
  222
+2 + 2 =3D 4
  223
+EOF
  224
+    mail = TMail::Mail.parse(msg)
  225
+    assert_equal "testing testing \326\244", mail.subject
  226
+    assert_equal "=?utf-8?Q?testing_testing_=D6=A4?=", mail.quoted_subject
  227
+    assert_equal "This is a test\n2 + 2 = 4\n", mail.body
  228
+    assert_equal "This_is_a_test\n2 + 2 =3D 4\n", mail.quoted_body
  229
+  end
  230
+
215 231
 end
216 232
 

0 notes on commit cb69736

Please sign in to comment.
Something went wrong with that request. Please try again.