Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/heliotrope/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def mime_content_for mime_part, preferred_type

mt = mime_type_for(mime_part) || "text/plain" # i guess
content_type = if mt =~ /^(.+);/ then $1.downcase else mt end
source_charset = if mt =~ /charset="?(.*?)"?(;|$)/i then $1 else "US-ASCII" end
source_charset = if mt =~ /charset\s*=\s*"?(.*?)"?(;|$)/i then $1 else "US-ASCII" end

content = mime_part.decode
converted_content, converted_charset = if(converter = CONVERSIONS[[content_type, preferred_type]])
Expand Down
57 changes: 57 additions & 0 deletions test/broken_charset.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Return-Path: <moodle@bar.invalid>
Date: Fri, 13 Apr 2012 12:00:02 +0200
Return-Path: moodle@bar.invalid
To: "Michael Stapelberg" <foo@bar.invalid>
From: "=?utf-8?B?THV0eiBTdHLDvG5nbWFubg==?=" <l.struengmann@bar.invalid>
Subject: =?utf-8?B?QUZTMjAxMjogQXVmZ2FiZW46IFB1bmt0ZSDDnGJ1bmcgMQ==?=
Message-ID: <0ba81486243611670b534d4564ee3718@localhost.localdomain>
X-Priority: 3
X-Mailer: PHPMailer [version Moodle 2007101590]
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_0ba81486243611670b534d4564ee3718"
X-DSPAM-Result: Innocent
X-DSPAM-Processed: Fri Apr 13 12:08:16 2012
X-DSPAM-Confidence: 0.9899
X-DSPAM-Probability: 0.0000
X-DSPAM-Signature: 4f87fb10319744089468961


--b1_0ba81486243611670b534d4564ee3718
Content-Type: text/plain; charset = "UTF-8"
Content-Transfer-Encoding: quoted-printable


AFS2012 -> Aufgaben -> Punkte =C3=9Cbung 1
---------------------------------------------------------------------
Lutz Str=C3=BCngmann hat einen Kommentar zu Ihrer eingereichten Aufgabe =
'Punkte
=C3=9Cbung 1' verfasst.

Sie finden ihn im Anhang Ihrer abgegebenen Aufgabe:

http://moodle.hs-mannheim.de/mod/assignment/view.php?id=3D11205
---------------------------------------------------------------------



--b1_0ba81486243611670b534d4564ee3718
Content-Type: text/html; charset = "UTF-8"
Content-Transfer-Encoding: quoted-printable

<p><font face=3D"sans-serif"><a =
href=3D"http://moodle.hs-mannheim.de/course/view.php?id=3D666">AFS2012</a> =
-><a href=3D"http://moodle.hs-mannheim.de/mod/assignment/index.php?id=3D66=
6">Aufgaben</a> -><a href=3D"http://moodle.hs-mannheim.de/mod/assignment/v=
iew.php?id=3D11205">Punkte =C3=9Cbung 1</a></font></p><hr /><font =
face=3D"sans-serif"><p>Lutz Str=C3=BCngmann hat einen Kommentar zu Ihrer =
abgegebenen Aufgabe verfasst.</i>'<i>Punkte =C3=9Cbung 1</i>'<br /><br />
Sie finden ihn im Anhang Ihrer=20
<a href=3D"http://moodle.hs-mannheim.de/mod/assignment/view.php?id=3D11205=
">eingereichten Aufgabe</a>:.</p></font><hr />



--b1_0ba81486243611670b534d4564ee3718--


12 changes: 12 additions & 0 deletions test/test_heliotrope.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# encoding: UTF-8

require 'test/unit'
require 'fileutils'
require 'digest/md5'
Expand Down Expand Up @@ -394,6 +396,16 @@ def test_labellist_pruning_removes_labels_without_corresponding_threads
assert_does_not_include "potato", @metaindex.all_labels
end

def test_recognize_charset
msg = nil
File.open('test/broken_charset.msg', 'r') do |f|
msg = Heliotrope::Message.new(f).parse!
end
assert_not_nil msg
mime_parts = msg.mime_parts "text/plain"
assert_equal mime_parts, [["text/plain; charset = \"utf-8\"", nil, nil, "\nAFS2012 -> Aufgaben -> Punkte Übung 1\n---------------------------------------------------------------------\nLutz Strüngmann hat einen Kommentar zu Ihrer eingereichten Aufgabe 'Punkte\nÜbung 1' verfasst.\n\nSie finden ihn im Anhang Ihrer abgegebenen Aufgabe:\n\nhttp://moodle.hs-mannheim.de/mod/assignment/view.php?id=11205\n---------------------------------------------------------------------\n\n\n"]]
end

private

def assert_includes v, set # standard one seems to have these things reversed
Expand Down