Skip to content

Commit 1564052

Browse files
Correct bug on parse destinatary data without email info.
Include tests and bug solution to invalid confirmation destinatary parse.
1 parent c5dae52 commit 1564052

5 files changed

Lines changed: 70 additions & 16 deletions

File tree

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,14 @@ public Address ReturnReceipt
563563
{
564564
get
565565
{
566-
if (HeaderFields["return-receipt-to"] != null) return Parser.ParseAddresses(HeaderFields.GetValues("return-receipt-to")[0])[0];
567-
else return null;
566+
if (HeaderFields["return-receipt-to"] != null)
567+
{
568+
var address = Parser.ParseAddresses(HeaderFields.GetValues("return-receipt-to")[0]);
569+
if (address.Count == 0) return null;
570+
return address[0];
571+
}
572+
else
573+
return null;
568574
}
569575
set
570576
{
@@ -617,7 +623,12 @@ public Address ConfirmRead
617623
{
618624
get
619625
{
620-
if (HeaderFields["disposition-notification-to"] != null) return Parser.ParseAddresses(HeaderFields.GetValues("disposition-notification-to")[0])[0];
626+
if (HeaderFields["disposition-notification-to"] != null)
627+
{
628+
var address = Parser.ParseAddresses(HeaderFields.GetValues("disposition-notification-to")[0]);
629+
if (address.Count == 0) return null;
630+
return address[0];
631+
}
621632
else return null;
622633
}
623634
set

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private static void ParseSubParts(ref MimePart part, Message message)
147147
if (string.IsNullOrWhiteSpace(strpart))
148148
continue;
149149

150-
int bounaryByteLen = GetASCIIByteCountOfPart(parentPartAsciiBody.Substring(0, parentPartAsciiBody.IndexOf(strpart)));
150+
int bounaryByteLen = GetASCIIByteCountOfPart(parentPartAsciiBody.Substring(0, parentPartAsciiBody.IndexOf(strpart)));
151151
int binaryPartLen = bounaryByteLen + GetASCIIByteCountOfPart(strpart);
152152
parentPartAsciiBody = null;
153153

@@ -178,7 +178,7 @@ private static void ParseSubParts(ref MimePart part, Message message)
178178
newpart.Container = part;
179179
part.SubParts.Add(newpart);
180180
}
181-
181+
182182
binaryBody = null;
183183
GC.Collect(GC.MaxGeneration);
184184
GC.WaitForPendingFinalizers();
@@ -474,7 +474,7 @@ private static void ParseHeaderFields(MimePart part, int headerEnd)
474474
part.ContentType = GetContentType(m.Value);
475475
else if (m.Value.ToLower().StartsWith("content-disposition:"))
476476
part.ContentDisposition = GetContentDisposition(m.Value);
477-
477+
478478
part.HeaderFields.Add(FormatFieldName(m.Value.Substring(0, m.Value.IndexOf(':'))), Codec.RFC2047Decode(m.Value.Substring(m.Value.IndexOf(':') + 1).Trim(' ', '\r', '\n')));
479479
part.HeaderFieldNames.Add(FormatFieldName(m.Value.Substring(0, m.Value.IndexOf(':'))), Codec.RFC2047Decode(m.Value.Substring(0, m.Value.IndexOf(':')).Trim(' ', '\r', '\n')));
480480
m = m.NextMatch();
@@ -497,7 +497,7 @@ private static void ParseBody(byte[] binaryData, MimePart part, int bodyStart)
497497
/// <returns></returns>
498498
public static MimePart ParseMimePart(byte[] binaryData, Message message)
499499
{
500-
MimePart part = new MimePart();
500+
MimePart part = new MimePart();
501501
part.ParentMessage = message;
502502
part.OriginalContent = ToASCII(binaryData); //ASCII content for header parsing
503503

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
102102
</Content>
103103
<None Include="packages.config" />
104+
<None Include="resource\confirm_read_parse_problem.eml">
105+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
106+
</None>
104107
<None Include="resource\multipart_with_type_using_camel_case.eml">
105108
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
106109
</None>

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,23 @@ public void should_return_resulting_date_in_utc()
3131

3232
utcDate.Kind.ShouldEqual(DateTimeKind.Utc);
3333
}
34-
34+
3535
[Test]
3636
public void should_parse_date_with_no_day_of_week()
3737
{
3838
var utcDate = Parser.ParseAsUniversalDateTime("24 Jun 2013 10:37:36 +0100");
3939

4040
utcDate.ShouldEqual(new DateTime(2013, 06, 24, 09, 37, 36));
4141
}
42-
42+
4343
[Test]
4444
public void should_parse_date_with_two_digits_year()
4545
{
4646
var utcDate = Parser.ParseAsUniversalDateTime("Mon, 24 Jun 13 10:37:36 +0100");
4747

4848
utcDate.ShouldEqual(new DateTime(2013, 06, 24, 09, 37, 36));
4949
}
50-
50+
5151
[Test]
5252
public void should_parse_date_with_no_seconds()
5353
{
@@ -104,9 +104,9 @@ public void should_parse_address_with_no_closing_quote_after_display_name()
104104
address.Name.ShouldEqual("Display Name only one quote");
105105
}
106106

107-
/// <summary>
108-
/// [discussion:641270] - Created discussion to validate if this test is rigth.
109-
/// </summary>
107+
/// <summary>
108+
/// [discussion:641270] - Created discussion to validate if this test is rigth.
109+
/// </summary>
110110
[Test]
111111
public void should_append_text_parts_with_inline_disposition()
112112
{
@@ -115,9 +115,9 @@ public void should_append_text_parts_with_inline_disposition()
115115
message.BodyText.Text.ShouldEqual("Good morning,\r\nThis is the body of the message.\r\n\r\nThis is the attached disclamer\r\n");
116116
}
117117

118-
/// <summary>
119-
/// [discussion:641270] - Created discussion to validate if this test is rigth.
120-
/// </summary>
118+
/// <summary>
119+
/// [discussion:641270] - Created discussion to validate if this test is rigth.
120+
/// </summary>
121121
[Test]
122122
public void should_append_html_parts_with_inline_disposition()
123123
{
@@ -156,5 +156,18 @@ public void ParseAttachmentWitoutFilename()
156156
for (int i = 0; i < message.Attachments.Count; i++)
157157
Assert.IsNotNull(message.Attachments[i].Filename);
158158
}
159+
/// <summary>
160+
/// Fields: Confirm-Reading-To, Return-Receipt-To, Disposition-Notification-To was indicated without e-mail address.
161+
/// RFC3798 has more information about details of parse https://tools.ietf.org/html/rfc3798
162+
/// NOTE: Without address the system will work with a null return on parse.
163+
/// </summary>
164+
[Test(Description = "ConfirmRead, DispositionNotificationTo and ReturnReceiptTo having exception.")]
165+
public void MustParseInvalidConfirmReadReturnReceipt()
166+
{
167+
Message message = Parser.ParseMessageFromFile("resource\\confirm_read_parse_problem.eml");
168+
Assert.IsNull(message.ConfirmRead);
169+
Assert.IsNull(message.ReturnReceipt);
170+
Assert.AreEqual(0, message.Recipients.Count);
171+
}
159172
}
160173
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Received: from MAIL.SERVER.NET ([127.0.0.1]) by
2+
MAIL.SERVER.NET ([127.0.0.1]) with mapi id 14.02.0318.004;
3+
Mon, 7 Jan 2013 07:07:07 +0100
4+
Received: from MAIL.SERVER.NET ([127.0.0.1]) by
5+
MAIL.SERVER.NET ([127.0.0.1]) with mapi id 14.02.0318.004;
6+
Sun, 6 Jan 2013 06:06:06 +0100
7+
Received: from MAIL.SERVER.NET ([127.0.0.1]) by
8+
MAIL.SERVER.NET ([127.0.0.1]) with mapi id 14.02.0318.004;
9+
Sat, 5 Jan 2013 05:05:05 +0100
10+
X-Confirm-Reading-To: Anonymous
11+
Return-Receipt-To: Anonymous
12+
Disposition-Notification-To: Anonymous
13+
reply-to: Anonymous
14+
15+
16+
Subject: betreff
17+
Thread-Topic: betreff
18+
Thread-Index: Ac3qMpl/+cj4AlTxTheZ0lsdxrLN2Q==
19+
Date: Fri, 4 Jan 2013 04:04:04 +0100
20+
Message-ID: <[email protected]>
21+
Accept-Language: de-DE, en-US
22+
Content-Language: de-DE
23+
Content-Type: multipart/mixed;
24+
boundary="_002_F92FF725718746429FB2067B724A2C9E33B5F5C2"
25+
MIME-Version: 1.0
26+
27+
--_002_F92FF725718746429FB2067B724A2C9E33B5F5C2--

0 commit comments

Comments
 (0)