aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2009-12-22 14:57:01 +0000
committerFrancis Irving <francis@mysociety.org>2009-12-22 14:57:01 +0000
commitb0de7bfd5388a552ef58235f8cb590ff2696f10c (patch)
treed454ed558185cb5c021b718e651bee82e084468f
parent69e8341c6f607838238e257c00fc916a09a6e5ee (diff)
Test for attaching attachments case, where the email attached is off
type octet-stream, so we don't know it is an email until later.
-rw-r--r--app/models/incoming_message.rb4
-rw-r--r--spec/fixtures/incoming-request-attach-attachments.email54
-rw-r--r--spec/models/incoming_message_spec.rb20
3 files changed, 76 insertions, 2 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index d0428fc81..42c80cef0 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -936,10 +936,10 @@ class IncomingMessage < ActiveRecord::Base
# Returns all attachments for use in display code
# XXX is this called multiple times and should be cached?
def get_attachments_for_display
- ensure_parts_counted
-
main_part = get_main_body_text_part
leaves = get_attachment_leaves
+ ensure_parts_counted
+
attachments = []
for leaf in leaves
if leaf != main_part
diff --git a/spec/fixtures/incoming-request-attach-attachments.email b/spec/fixtures/incoming-request-attach-attachments.email
new file mode 100644
index 000000000..efcf1a4d1
--- /dev/null
+++ b/spec/fixtures/incoming-request-attach-attachments.email
@@ -0,0 +1,54 @@
+From francis@localhost Tue Dec 22 14:34:49 2009
+From: Francis Irving <francis@localhost>
+To: test@localhost
+Subject: This is a test
+MIME-Version: 1.0
+Content-Type: multipart/mixed; boundary="V0207lvV8h4k8FAm"
+Content-Disposition: inline
+X-Mutt-Fcc: =uniheap
+Status: RO
+Content-Length: 852
+Lines: 42
+
+
+--V0207lvV8h4k8FAm
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+
+Attached is an email containing attachments.
+
+Francis
+
+--V0207lvV8h4k8FAm
+Content-Type: application/octet-stream; charset=us-ascii
+Content-Disposition: attachment; filename="incoming-request-two-same-name.email"
+
+From: EMAIL_FROM
+To: FOI Person <foi_person@localhost>
+Subject: Same attachment twice
+Content-Type: multipart/mixed; boundary="Q68bSM7Ycu6FN28Q"
+Content-Disposition: inline
+
+
+--Q68bSM7Ycu6FN28Q
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: inline
+
+
+
+--Q68bSM7Ycu6FN28Q
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: attachment; filename="hello.txt"
+
+Second hello
+
+--Q68bSM7Ycu6FN28Q
+Content-Type: text/plain; charset=us-ascii
+Content-Disposition: attachment; filename="hello.txt"
+
+First hello
+
+--Q68bSM7Ycu6FN28Q--
+
+
+--V0207lvV8h4k8FAm--
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index f08f1338c..71d8da647 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -228,4 +228,24 @@ describe IncomingMessage, " when uudecoding bad messages" do
end
+describe IncomingMessage, "when messages are attached to messages" do
+ it "should flatten all the attachments out" do
+ mail_body = load_file_fixture('incoming-request-attach-attachments.email')
+ mail = TMail::Mail.parse(mail_body)
+ mail.base64_decode
+
+ im = IncomingMessage.new
+ im.stub!(:mail).and_return(mail)
+ ir = InfoRequest.new
+ im.info_request = ir
+
+ attachments = im.get_attachments_for_display
+ attachments.size.should == 3
+ attachments[0].display_filename.should == 'Same attachment twice.txt'
+ attachments[1].display_filename.should == 'hello.txt'
+ attachments[2].display_filename.should == 'hello.txt'
+ end
+end
+
+