attachments 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'uuidtools'
3
+ require 'fileutils'
3
4
  require 'mail'
4
5
 
5
6
 
@@ -21,7 +22,7 @@ module Attachments
21
22
 
22
23
  def close
23
24
  files.each do |f|
24
- FileUtils::rm(f[:filename])
25
+ FileUtils::rm(f[:tmpfile])
25
26
  end
26
27
  reset
27
28
  end
@@ -97,9 +98,22 @@ module Attachments
97
98
  filename = "#{@name}.#{uuid}"
98
99
  filepath = "/tmp/#{filename}"
99
100
 
101
+ body = case ct
102
+ when "text/plain" then
103
+ m = mail.body.decoded
104
+ begin
105
+ m.encode("utf-8")
106
+ rescue
107
+ # Ruby 1.8 doesn't know encode
108
+ m
109
+ end
110
+ else
111
+ mail.body.decoded
112
+ end
113
+
100
114
  # Save part as it is of a supported type
101
115
  f = File.new(filepath, "wb")
102
- f.write(mail.body.decoded)
116
+ f.write(body)
103
117
  f.close
104
118
 
105
119
  unless File.exists?(filepath)
@@ -0,0 +1,48 @@
1
+ Return-Path: <rune@epubify.com>
2
+ X-Original-To: posterous@boox.epubify.com
3
+ Delivered-To: posterous@boox.epubify.com
4
+ Received: from mail-gw0-f51.google.com (mail-gw0-f51.google.com [74.125.83.51])
5
+ by boox (Postfix) with ESMTP id 053CEA8805
6
+ for <posterous@boox.epubify.com>; Fri, 13 Aug 2010 11:53:59 +0000 (UTC)
7
+ Received: by gwb17 with SMTP id 17so702822gwb.38
8
+ for <posterous@boox.epubify.com>; Fri, 13 Aug 2010 04:53:40 -0700 (PDT)
9
+ MIME-Version: 1.0
10
+ Received: by 10.151.111.1 with SMTP id o1mr1964300ybm.26.1281700420730; Fri,
11
+ 13 Aug 2010 04:53:40 -0700 (PDT)
12
+ Received: by 10.150.217.13 with HTTP; Fri, 13 Aug 2010 04:53:40 -0700 (PDT)
13
+ X-Originating-IP: [84.208.65.71]
14
+ Date: Fri, 13 Aug 2010 13:53:40 +0200
15
+ Message-ID: <AANLkTimsuBB4r-9rEW3iUd49hb1EnEyX58+eyxqQyeFs@mail.gmail.com>
16
+ Subject: Test
17
+ From: Rune Myrland <rune@epubify.com>
18
+ To: posterous@boox.epubify.com
19
+ Content-Type: multipart/alternative; boundary=001517576834493df4048db32256
20
+
21
+ --001517576834493df4048db32256
22
+ Content-Type: text/plain; charset=ISO-8859-1
23
+ Content-Transfer-Encoding: quoted-printable
24
+
25
+ ! Overskrift
26
+
27
+ Litt test.
28
+
29
+ !! En underoverskrift.
30
+
31
+ Og s=E5
32
+
33
+ -. Si noe da!
34
+
35
+ -. Hva da?
36
+
37
+ -. Hva som helst?
38
+
39
+ --001517576834493df4048db32256
40
+ Content-Type: text/html; charset=ISO-8859-1
41
+ Content-Transfer-Encoding: quoted-printable
42
+
43
+ <div>! Overskrift<br></div><div><br></div><div>Litt test.</div><div><br></d=
44
+ iv><div>!! En underoverskrift.</div><div><br></div><div>Og s=E5</div><div><=
45
+ br></div><div>-. Si noe da!</div><div><br></div><div>-. Hva da?</div><div>
46
+ <br></div><div>-. Hva som helst?</div><div><br></div>
47
+
48
+ --001517576834493df4048db32256--
@@ -1,7 +1,33 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestAttachments < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ def setup
5
+ @extract = Attachments::Extract.new [ "text/plain" ]
6
+ @extract.parse "./test/data/mail_0001.eml"
7
+ end
8
+
9
+ def teardown
10
+ @extract.close
11
+ end
12
+
13
+ should "extract a part mail_001" do
14
+ assert_equal(@extract.files.length, 1)
15
+ end
16
+
17
+ should "extract part of type text/plain" do
18
+ assert_equal(@extract.files[0][:mime_type], "text/plain")
19
+ end
20
+
21
+ should "create files from the attachments" do
22
+ @extract.files.each do |f|
23
+ assert File::exists?(f[:tmpfile])
24
+ puts f.inspect
25
+ end
26
+ end
27
+
28
+ should "remove tmp files on close" do
29
+ tmpfile = @extract.files[0][:tmpfile]
30
+ @extract.close
31
+ assert !File::exists?(tmpfile)
6
32
  end
7
33
  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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rune Myrland
@@ -69,6 +69,7 @@ files:
69
69
  - lib/attachments.rb
70
70
  - lib/attachments/extract.rb
71
71
  - lib/attachments/filemagic.rb
72
+ - test/data/mail_0001.eml
72
73
  - test/helper.rb
73
74
  - test/test_attachments.rb
74
75
  has_rdoc: true