aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-06-06 16:06:26 +0000
committerJamis Buck <jamis@37signals.com>2005-06-06 16:06:26 +0000
commitcf1e2a84fff32ab1cf2a736bb99c53e830d92db3 (patch)
tree0fb88beb26786057a35232067e479f4b2b0e80d6
parent5add31eda48aa2db61ee0c76d3d8bc5a0992e6f5 (diff)
downloadrails-cf1e2a84fff32ab1cf2a736bb99c53e830d92db3.tar.gz
rails-cf1e2a84fff32ab1cf2a736bb99c53e830d92db3.tar.bz2
rails-cf1e2a84fff32ab1cf2a736bb99c53e830d92db3.zip
Handle parsing of recursively multipart messages
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1389 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionmailer/CHANGELOG2
-rw-r--r--actionmailer/lib/action_mailer/vendor/tmail/quoting.rb13
-rw-r--r--actionmailer/test/fixtures/raw_email756
-rwxr-xr-xactionmailer/test/mail_service_test.rb6
4 files changed, 74 insertions, 3 deletions
diff --git a/actionmailer/CHANGELOG b/actionmailer/CHANGELOG
index 632791d8af..567025126b 100644
--- a/actionmailer/CHANGELOG
+++ b/actionmailer/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Nested multipart message parts are correctly processed in TMail::Mail#body
+
* BCC headers are removed when sending via SMTP #1402
* Added 'content_type' accessor, to allow content type to be set on a per-message basis. content_type defaults to "text/plain".
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
index 43e834b2a6..4420f2ea6b 100644
--- a/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
+++ b/actionmailer/lib/action_mailer/vendor/tmail/quoting.rb
@@ -28,9 +28,16 @@ module TMail
if multipart?
parts.collect { |part|
header = part["content-type"]
- header && header.main_type == "text" ?
- part.unquoted_body(to_charset) :
- (header ? attachment_presenter.call(header.params["name"]) : "")
+
+ if part.multipart?
+ part.body(to_charset, &attachment_presenter)
+ elsif header.nil?
+ ""
+ elsif header.main_type == "text"
+ part.unquoted_body(to_charset)
+ else
+ attachment_presenter.call(header["name"] || "(unnamed)")
+ end
}.join
else
unquoted_body(to_charset)
diff --git a/actionmailer/test/fixtures/raw_email7 b/actionmailer/test/fixtures/raw_email7
new file mode 100644
index 0000000000..251172a71f
--- /dev/null
+++ b/actionmailer/test/fixtures/raw_email7
@@ -0,0 +1,56 @@
+Mime-Version: 1.0 (Apple Message framework v730)
+Content-Type: multipart/mixed; boundary=Apple-Mail-13-196941151
+Message-Id: <9169D984-4E0B-45EF-82D4-8F5E53AD7012@example.com>
+From: foo@example.com
+Subject: testing
+Date: Mon, 6 Jun 2005 22:21:22 +0200
+To: blah@example.com
+
+
+--Apple-Mail-13-196941151
+Content-Type: multipart/mixed;
+ boundary=Apple-Mail-12-196940926
+
+
+--Apple-Mail-12-196940926
+Content-Transfer-Encoding: quoted-printable
+Content-Type: text/plain;
+ charset=ISO-8859-1;
+ delsp=yes;
+ format=flowed
+
+This is the first part.
+
+--Apple-Mail-12-196940926
+Content-Transfer-Encoding: base64
+Content-Type: application/pdf;
+ x-unix-mode=0666;
+ name="test.pdf"
+Content-Disposition: inline;
+ filename=test.pdf
+
+YmxhaCBibGFoIGJsYWg=
+
+--Apple-Mail-12-196940926
+Content-Transfer-Encoding: 7bit
+Content-Type: text/plain;
+ charset=US-ASCII;
+ format=flowed
+
+
+
+--Apple-Mail-12-196940926--
+
+--Apple-Mail-13-196941151
+Content-Transfer-Encoding: base64
+Content-Type: application/pkcs7-signature;
+ name=smime.p7s
+Content-Disposition: attachment;
+ filename=smime.p7s
+
+jamisSqGSIb3DQEHAqCAMIjamisxCzAJBgUrDgMCGgUAMIAGCSqGSjamisEHAQAAoIIFSjCCBUYw
+ggQujamisQICBD++ukQwDQYJKojamisNAQEFBQAwMTELMAkGA1UEBhMCRjamisAKBgNVBAoTA1RE
+QzEUMBIGjamisxMLVERDIE9DRVMgQ0jamisNMDQwMjI5MTE1OTAxWhcNMDYwMjamisIyOTAxWjCB
+gDELMAkGA1UEjamisEsxKTAnBgNVBAoTIEjamisuIG9yZ2FuaXNhdG9yaXNrIHRpbjamisRuaW5=
+
+--Apple-Mail-13-196941151--
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index 3695aa1a15..9f0e51716f 100755
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -497,5 +497,11 @@ EOF
assert_match %r{^To: #{@recipient}}, MockSMTP.deliveries[0][0]
assert_no_match %r{^Bcc: root@loudthinking.com}, MockSMTP.deliveries[0][0]
end
+
+ def test_recursive_multipart_processing
+ fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email7")
+ mail = TMail::Mail.parse(fixture)
+ assert_equal "This is the first part.\n\nAttachment: test.pdf\n\n\nAttachment: smime.p7s\n", mail.body
+ end
end