{"action":"created","issue":{"url":"https://api.github.com/repos/andrewdavey/postal/issues/158","repository_url":"https://api.github.com/repos/andrewdavey/postal","labels_url":"https://api.github.com/repos/andrewdavey/postal/issues/158/labels{/name}","comments_url":"https://api.github.com/repos/andrewdavey/postal/issues/158/comments","events_url":"https://api.github.com/repos/andrewdavey/postal/issues/158/events","html_url":"https://github.com/andrewdavey/postal/issues/158","id":172758545,"number":158,"title":"An invalid character was found in the mail header: ';'.","user":{"login":"trailmax","id":3606356,"avatar_url":"https://avatars.githubusercontent.com/u/3606356?v=3","gravatar_id":"","url":"https://api.github.com/users/trailmax","html_url":"https://github.com/trailmax","followers_url":"https://api.github.com/users/trailmax/followers","following_url":"https://api.github.com/users/trailmax/following{/other_user}","gists_url":"https://api.github.com/users/trailmax/gists{/gist_id}","starred_url":"https://api.github.com/users/trailmax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trailmax/subscriptions","organizations_url":"https://api.github.com/users/trailmax/orgs","repos_url":"https://api.github.com/users/trailmax/repos","events_url":"https://api.github.com/users/trailmax/events{/privacy}","received_events_url":"https://api.github.com/users/trailmax/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-23T17:27:17Z","updated_at":"2016-08-30T09:53:18Z","closed_at":null,"body":"I've discovered an interesting bug. Today in production logs I've found the following exception:\r\n\r\n>System.FormatException: An invalid character was found in the mail header: ';'.\r\n>   at System.Net.Mail.MailAddressParser.ParseLocalPart(String data, Int32& index, Boolean expectAngleBracket, Boolean expectMultipleAddresses)\r\n>   at System.Net.Mail.MailAddressParser.ParseAddress(String data, Boolean expectMultipleAddresses, Int32& index)\r\n>   at System.Net.Mail.MailAddressParser.ParseMultipleAddresses(String data)\r\n>   at System.Net.Mail.MailAddressCollection.ParseValue(String addresses)\r\n\r\nI've tracked the issue to an email with an apostrophe. Something like `Mr.O'Neil@example.com' when using a strongly typed email:\r\n\r\n    public class TestEmail : Postal.Email\r\n    {\r\n        public string To { get; set; }\r\n        public int Name { get; set; }\r\n    }\r\n\r\n\r\n    @model TestEmail\r\n    To: @Model.Name <@Model.To>\r\n    Subject: Fail Test\r\n\r\n    Hello world\r\n\r\n\r\n    var email = new TestEmail(){\r\n        To = \"Mr.O'Neil@example.com\",\r\n        Name = \"Mr O'Neil\",\r\n    }\r\n    email.Send(); // this will explode with the exception\r\n\r\nThe problem tracks down to RazorEngine doing encoding of all the input. So `Mr.O'Neil@example.com` is getting translated into `Mr.O&#39;Neil@example.com`. You see where the problem comes from? When trying to add this value to `MailMessage.To` - the above exception is thrown.\r\n\r\nNow I've attempted to replace `@Model.To` with `@Html.Raw(Model.To)`, but Razor Engine fails with message \"HtmlHelper is not available\". \r\n\r\nSolution I've found is to use `RawString` in `cshtml` template:\r\n\r\n    To: @(new RawString(Model.To))\r\n\r\nBut this adds mental overhead and can easily be forgotten when adding new templates. Any ideas how to improve?"},"comment":{"url":"https://api.github.com/repos/andrewdavey/postal/issues/comments/243390443","html_url":"https://github.com/andrewdavey/postal/issues/158#issuecomment-243390443","issue_url":"https://api.github.com/repos/andrewdavey/postal/issues/158","id":243390443,"user":{"login":"trailmax","id":3606356,"avatar_url":"https://avatars.githubusercontent.com/u/3606356?v=3","gravatar_id":"","url":"https://api.github.com/users/trailmax","html_url":"https://github.com/trailmax","followers_url":"https://api.github.com/users/trailmax/followers","following_url":"https://api.github.com/users/trailmax/following{/other_user}","gists_url":"https://api.github.com/users/trailmax/gists{/gist_id}","starred_url":"https://api.github.com/users/trailmax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trailmax/subscriptions","organizations_url":"https://api.github.com/users/trailmax/orgs","repos_url":"https://api.github.com/users/trailmax/repos","events_url":"https://api.github.com/users/trailmax/events{/privacy}","received_events_url":"https://api.github.com/users/trailmax/received_events","type":"User","site_admin":false},"created_at":"2016-08-30T09:53:18Z","updated_at":"2016-08-30T09:53:18Z","body":"We are using `RazorGenerator.MsBuild` - it compiles all the *.cshtml files and `@Raw()` trips the compile process, so that is a no-go unfortunately. `RawString` works just the same. The problem is having to remember to do it in every email template for every header that might have special characters. But I don't think there will be a work-around to that, other than some integration test that will go through every email template and verify that `RawString` is applied."}}
{"actor":{"display_login":"trailmax"}}