Skip to content

Commit cc9ee00

Browse files
committed
Fixed Reply & Forward examples to handle null message subjects
1 parent 9f76ab0 commit cc9ee00

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

FAQ.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -838,8 +838,8 @@ public static MimeMessage Reply (MimeMessage message, MailboxAddress from, bool
838838
}
839839

840840
// set the reply subject
841-
if (!message.Subject.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
842-
reply.Subject = "Re: " + message.Subject;
841+
if (!message.Subject?.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
842+
reply.Subject = "Re: " + (message.Subject ?? string.Empty);
843843
else
844844
reply.Subject = message.Subject;
845845

@@ -964,8 +964,8 @@ public class ReplyVisitor : MimeVisitor
964964
}
965965

966966
// set the reply subject
967-
if (!message.Subject.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
968-
reply.Subject = "Re: " + message.Subject;
967+
if (!message.Subject?.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
968+
reply.Subject = "Re: " + (message.Subject ?? string.Empty);
969969
else
970970
reply.Subject = message.Subject;
971971

@@ -1141,8 +1141,8 @@ public static MimeMessage Forward (MimeMessage original, MailboxAddress from, IE
11411141
message.To.AddRange (to);
11421142

11431143
// set the forwarded subject
1144-
if (!original.Subject.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
1145-
message.Subject = "FW: " + original.Subject;
1144+
if (!original.Subject?.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
1145+
message.Subject = "FW: " + (original.Subject ?? string.Empty);
11461146
else
11471147
message.Subject = original.Subject;
11481148

@@ -1174,16 +1174,16 @@ public static MimeMessage Forward (MimeMessage original, MailboxAddress from, IE
11741174
message.To.AddRange (to);
11751175

11761176
// set the forwarded subject
1177-
if (!original.Subject.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
1178-
message.Subject = "FW: " + original.Subject;
1177+
if (!original.Subject?.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
1178+
message.Subject = "FW: " + (original.Subject ?? string.Empty);
11791179
else
11801180
message.Subject = original.Subject;
11811181

11821182
// quote the original message text
11831183
using (var text = new StringWriter ()) {
11841184
text.WriteLine ();
11851185
text.WriteLine ("-------- Original Message --------");
1186-
text.WriteLine ("Subject: {0}", original.Subject);
1186+
text.WriteLine ("Subject: {0}", original.Subject ?? string.Empty);
11871187
text.WriteLine ("Date: {0}", DateUtils.FormatDate (original.Date));
11881188
text.WriteLine ("From: {0}", original.From);
11891189
text.WriteLine ("To: {0}", original.To);

0 commit comments

Comments
 (0)