Sicos1977 / MsgKit

A .NET library to make MSG files without the need for Outlook
204 stars 56 forks source link

Fix Substring error on subjects shorter than 5 characters #6

Closed tlecomte closed 7 years ago

tlecomte commented 7 years ago

Hi Sicos1977

Here is a pull request to fix an error that occurs when a message subject is shorter than 5 characters. In that case, the following exception was obtained:

System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. Parameter name: startIndex at System.String.Substring(Int32 startIndex, Int32 length) at MsgKit.Email.SetSubject() in ...\MsgKit\Email.cs:line 265 at MsgKit.Email..ctor(Sender sender, String subject) in ...\MsgKit\Email.cs:line 102

Thanks for looking at this pull request, and thanks for MsgKit!

tlecomte commented 7 years ago

After a closer look, it seems that the usage of Substring was not right according to the intent of the code (Substring(x) takes what is after x, not before). Using a Regex makes it easier to define the prefix.

Sicos1977 commented 7 years ago

Thanks for the pull request.