Skip to content

Commit

Permalink
Fixed Reply & Forward examples to handle null message subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Mar 6, 2024
1 parent 9f76ab0 commit cc9ee00
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,8 @@ public static MimeMessage Reply (MimeMessage message, MailboxAddress from, bool
}

// set the reply subject
if (!message.Subject.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
reply.Subject = "Re: " + message.Subject;
if (!message.Subject?.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
reply.Subject = "Re: " + (message.Subject ?? string.Empty);
else
reply.Subject = message.Subject;

Expand Down Expand Up @@ -964,8 +964,8 @@ public class ReplyVisitor : MimeVisitor
}

// set the reply subject
if (!message.Subject.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
reply.Subject = "Re: " + message.Subject;
if (!message.Subject?.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
reply.Subject = "Re: " + (message.Subject ?? string.Empty);
else
reply.Subject = message.Subject;

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

// set the forwarded subject
if (!original.Subject.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
message.Subject = "FW: " + original.Subject;
if (!original.Subject?.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
message.Subject = "FW: " + (original.Subject ?? string.Empty);
else
message.Subject = original.Subject;

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

// set the forwarded subject
if (!original.Subject.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
message.Subject = "FW: " + original.Subject;
if (!original.Subject?.StartsWith ("FW:", StringComparison.OrdinalIgnoreCase))
message.Subject = "FW: " + (original.Subject ?? string.Empty);
else
message.Subject = original.Subject;

// quote the original message text
using (var text = new StringWriter ()) {
text.WriteLine ();
text.WriteLine ("-------- Original Message --------");
text.WriteLine ("Subject: {0}", original.Subject);
text.WriteLine ("Subject: {0}", original.Subject ?? string.Empty);
text.WriteLine ("Date: {0}", DateUtils.FormatDate (original.Date));
text.WriteLine ("From: {0}", original.From);
text.WriteLine ("To: {0}", original.To);
Expand Down

0 comments on commit cc9ee00

Please sign in to comment.