Skip to content

Commit ee75b61

Browse files
Support to process Header only emails.
1 parent 6b90286 commit ee75b61

6 files changed

Lines changed: 61 additions & 7 deletions

File tree

16 KB
Binary file not shown.

Class Library/ActiveUp.Net.Common/MimeBody.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public string Text
8484
else
8585
return ProductHelper.GetTrialString(this._text, TrialStringType.LongText);
8686
#else
87-
string ret = _text;
87+
string ret = _text ?? "";
8888
ret = ret.Replace("FLAGS (Seen)", string.Empty);
8989
return ret;
9090
#endif

Class Library/ActiveUp.Net.Common/Parser.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,14 @@ public static MimePart ParseMimePart(byte[] binaryData, Message message)
530530
var headerEnd = Regex.Match(part.OriginalContent, @".(?=\r?\n\r?\n)").Index + 1;
531531
var bodyStart = Regex.Match(part.OriginalContent, @"(?<=\r?\n\r?\n).").Index;
532532

533-
//TODO: remove this workaround
534-
if (bodyStart == 0)
533+
// Solve header only situations.
534+
if (bodyStart == 0 && headerEnd == 1)
535535
{
536-
var indexBody = part.OriginalContent.IndexOf("\r\n\r\n");
537-
if (indexBody > 0)
538-
bodyStart = indexBody;
536+
ParseHeaderFields(part, part.OriginalContent.Length);
537+
return part;
539538
}
539+
540+
// Process Header and Body
540541
if (part.OriginalContent.Length >= headerEnd)
541542
{
542543
ParseHeaderFields(part, headerEnd);

Class Library/ActiveUp.Net.Tests/ActiveUp.Net.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
<None Include="resource\multipart_body_text_and_html.eml">
134134
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
135135
</None>
136+
<None Include="resource\only_header.eml">
137+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
138+
</None>
136139
<None Include="resource\quoted-printable-notepad-linebreak.eml">
137140
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
138141
</None>

Class Library/ActiveUp.Net.Tests/Common/ParserTests.cs

Lines changed: 12 additions & 1 deletion
Large diffs are not rendered by default.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Received: (qmail 54705 invoked by uid 89); 28 Aug 2017 14:51:48 -0300
2+
Delivered-To: [email protected]
3+
Received: (qmail 54686 invoked from network); 28 Aug 2017 14:51:47 -0300
4+
Received: by simscan 1.4.0 ppid: 54607, pid: 54648, t: 2.9204s
5+
scanners: clamav: 0.99.2/m:/d:23727 spam: 3.4.1
6+
X-Spam-Checker-Version: SpamAssassin: -last, FreeBSD Brasil LTDA rulesets: Yes
7+
X-Spam-Status: No, hits=-1.6 required=5.0
8+
Received: from unknown ([200.147.97.220])
9+
(envelope-sender <[email protected]>)
10+
by color.serveru.us (qmail-ldap-1.03) with SMTP
11+
for <[email protected]>; 28 Aug 2017 14:51:44 -0300
12+
Received: from localhost (localhost.localdomain [127.0.0.1])
13+
by a4-salsa1.host.com.br (Postfix) with ESMTP id C56FB380009F
14+
for <[email protected]>; Mon, 28 Aug 2017 14:55:45 -0300 (BRT)
15+
Received: from a4-salsa1.host.intranet (localhost.localdomain [127.0.0.1])
16+
by a4-salsa1.host.com.br (Postfix) with ESMTP id AD4CF380009B
17+
for <[email protected]>; Mon, 28 Aug 2017 14:55:45 -0300 (BRT)
18+
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=host.com.br; s=afl;
19+
t=1503942945; bh=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN/XKdLCPjaYaY=;
20+
h=Date:From:To:In-Reply-To:References:Subject;
21+
b=ikMN+aVF4eIDnS6T6mrnzUNHPBtTqrZJgTuZh3dPK/WqrE5JQzp6izefol5kMNHyi
22+
1CLGtQ3UutOWtdD1g2JsugJD0SrwuVGxQ9bkcTZX6zRkkETnPKJj/Y6XBxHrSZhWEd
23+
2Zq0nQLoGZOwDDzwWoHHUpnKasVy7TXHp8/NrBO4=
24+
Received: from localhost (a4-winter6.host.intranet [10.131.133.132])
25+
by a4-salsa1.host.intranet (Postfix) with ESMTP id A51303800081
26+
for <[email protected]>; Mon, 28 Aug 2017 14:55:45 -0300 (BRT)
27+
Date: Mon, 28 Aug 2017 14:55:45 -0300
28+
29+
30+
Message-ID: <[email protected]>
31+
In-Reply-To:
32+
References:
33+
Subject: I'm put all my text message on subject, then no has body in this e-mail.
34+
second line exists too.
35+
Mime-Version: 1.0
36+
Content-Type: text/html
37+
Content-Transfer-Encoding: 7bit
38+
X-SenderIP: 200.164.35.146
39+
X-SIG5: d41d8cd98f00b204e9800998ecf8427e

0 commit comments

Comments
 (0)