Repository: getsentry/sentry

Issue:
Problem with the encoding
Data:

```
Error processing post_process() on "<class 'sentry.plugins.sentry_mail.MailProcessor'>": UnicodeDecodeError('ascii', '\n<!DOCTYPE html>\n<html style="font-size: 12px">\n<head style="font-size: 12px">\n\n</head>\n<body style=\'font-size: 12px; width: 100%; font-family: "helvetica neue", helvetica, sans-serif; border: 0; padding: 0; margin: 0\'>\n<table class="main level-30" style=\'font-size: 12px; width: 100%; font-family: "helvetica neue", helvetica, sans-serif; border: 0; padding: 0; margin: 0\'>\n<tr style="font-size: 12px">\n<td style="font-size: 12px; padding: 0; margin: 0; text-align: center">\n<div class="body" style="font-size: 12px; margin: 0 auto; text-align: left; width: 600px; border: 5px solid #404f60">\n<div class="header" style="font-size: 14px; background: #404f60; color: #fff; padding: 10px; height: 28px">\n<h1 style="font-size: 22px; float: left; margin: 0; padding: 0">Sentry <small style="font-size: 14px; margin-left: 10px; color: #ccc; font-weight: normal">\n                                \n                                    New Event\n                                \n                            </small></h1>\n<span class="count" style=\'font-size: 16px; color: #fff; float: right; margin: -18px -10px 0 10px; -moz-border-radius: 60px; -webkit-border-radius: 60px; border-radius: 60px; width: 60px; height: 60px; background: #ffa101; line-height: 62px; text-align: center; font-weight: 400; font-family: "proxima nova", "proxima-nova", "heletica-neue", sans-serif\'>1</span>\n</div>\n<div class="inner" style="font-size: 12px; background: #fff; padding: 10px">\n<p style="font-size: 12px; margin-bottom: 15px">E_WARNING: unlink() [&lt;a href=&#39;function.unlink&#39;&gt;function.unlink&lt;/a&gt;]: nen\xc3\xad souborem ani adres\xc3\xa1\xc5\x99em</p>\n<p style="font-size: 12px; margin-bottom: 15px"><a href="http://xxx/2/group/6/" style="font-size: 12px">http://xxx/2/group/6/</a></p>\n<table style="font-size: 12px; width: 100%; margin-bottom: 15px">\n<colgroup style="font-size: 12px">\n<col style="font-size: 12px; width:25%;" />\n<col style="font-size: 12px; width:25%;" />\n<col style="font-size: 12px; width:25%;" />\n<col style="font-size: 12px; width:25%;" />\n</colgroup>\n<tr style="font-size: 12px">\n<th style="font-size: 12px; text-align: left">Logger:</th>\n<td style="font-size: 12px; padding: 0; margin: 0; text-align: left">irest2</td>\n<th style="font-size: 12px; text-align: left">Level:</th>\n<td style="font-size: 12px; padding: 0; margin: 0; text-align: left">warning</td>\n</tr>\n<tr style="font-size: 12px">\n<th style="font-size: 12px; text-align: left">Server:</th>\n<td style="font-size: 12px; padding: 0; margin: 0; text-align: left">irestFE2</td>\n<th style="font-size: 12px; text-align: left">First Seen:</th>\n<td style="font-size: 12px; padding: 0; margin: 0; text-align: left">April 10, 2012</td>\n</tr>\n</table>\n<div class="interface" style="font-size: 12px; margin-bottom: 15px">\n<div class="title" style="font-size: 14px; color: #404f60; padding-bottom: 5px; margin-bottom: 5px; border-bottom: 1px solid #404f60; font-weight: bold">Stacktrace</div>\n<pre style=\'font-size: 11px; font-family: Menlo, Monaco, "Courier New", monospace; margin-bottom: 15px\'>Stacktrace (most recent call last):\n\n  File &quot;/data/www/FE_IREST/app2/public/index.php&quot;, line 58, in run\n    $application-&gt;run();\n\n  File &quot;/data/www/FE_IREST/app2/library/Zend/Application.php&quot;, line 366, in run\n    $this-&gt;getBootstrap()-&gt;run();\n\n  File &quot;/data/www/FE_IREST/app2/library/Zend/Application/Bootstrap/Bootstrap.php&quot;, line 97, in dispatch\n    $response = $front-&gt;dispatch();\n\n  File &quot;/data/www/FE_IREST/app2/library/Zend/Controller/Front.php&quot;, line 954, in dispatch\n    $dispatcher-&gt;dispatch($this-&gt;_request, $this-&gt;_response);\n\n  File &quot;/data/www/FE_IREST/app2/library/Zend/Controller/Dispatcher/Standard.php&quot;, line 295, in dispatch\n    $controller-&gt;dispatch($action);\n\n  File &quot;/data/www/FE_IREST/app2/library/Zend/Controller/Action.php&quot;, line 513, in editAction\n    $this-&gt;$action();\n\n  File &quot;/data/www/FE_IREST/app2/application/controllers/ListingimageController.php&quot;, line 144, in processImage\n    $componentImageDelete-&gt;processImage($image);\n\n  File &quot;/data/www/FE_IREST/app2/library/Irest/Controller/Component/Listing/Image/Delete.php&quot;, line 64, in array_map\n    \\array_map($rm, $imageModel-&gt;getPaths());\n\n  File &quot;[Anonymous function]&quot;, line 0, in Irest\\Controller\\Component\\Listing\\Image\\{closure}\n    Irest\\Controller\\Component\\Listing\\Image\\{closure}(Array)\n\n  File &quot;/data/www/FE_IREST/app2/library/Irest/Controller/Component/Listing/Image/Delete.php&quot;, line 59, in unlink\n    $result = \\unlink($filename);\n\n  File &quot;[Anonymous function]&quot;, line 0, in Irest\\Bootstrap\\{closure}\n    Irest\\Bootstrap\\{closure}(Array)\n</pre>\n</div>\n<div class="interface" style="font-size: 12px; margin-bottom: 15px">\n<div class="title" style="font-size: 14px; color: #404f60; padding-bottom: 5px; margin-bottom: 5px; border-bottom: 1px solid #404f60; font-weight: bold">Http</div>\n<pre style=\'font-size: 11px; font-family: Menlo, Monaco, "Courier New", monospace; margin-bottom: 15px\'>\n<table style="font-size: 12px; width: 100%; margin-bottom: 15px">\n    <colgroup style="font-size: 12px">\n        <col style="font-size: 12px; width:60px;" />\n    </colgroup>\n    <tbody style="font-size: 12px">\n        <tr style="font-size: 12px">\n            <th style="font-size: 12px; text-align: left">URL:</th>\n            <td style="font-size: 12px; padding: 0; margin: 0; text-align: left"><a href="http://irest2.irest.cz/listing/edit/889/image/edit" style="font-size: 12px">http://irest2.irest.cz/listing/edit/889/image/edit</a></td>\n        </tr>\n        \n            <tr style="font-size: 12px">\n                <th style="font-size: 12px; text-align: left">Method:</th>\n                <td style="font-size: 12px; padding: 0; margin: 0; text-align: left">POST</td>\n            </tr>\n        \n        <tr style="font-size: 12px">\n            <th style="font-size: 12px; text-align: left">Query:</th>\n            <td style="font-size: 12px; padding: 0; margin: 0; text-align: left">\n                <code style=\'font-size: 11px; font-family: Menlo, Monaco, "Courier New", monospace\'>&#39;&#39;</code>\n            </td>\n        </tr>\n    </tbody>\n</table></pre>\n</div>\n</div>\n</div>\n</td>\n</tr>\n</table>\n</body>\n</html>', 1599, 1600, 'ordinal not in range(128)')
```

Stacktrace (most recent call last):

  File "sentry/processors/base.py", line 24, in send_group_processors
    logger.exception('Error processing post_process() on %r: %s', inst.**class**, e)

  File "sentry/plugins/sentry_mail/**init**.py", line 184, in post_process
    self.mail_members(group, event)

  File "sentry/plugins/sentry_mail/**init**.py", line 145, in mail_members
    'interfaces': interface_list,

  File "pynliner/**init**.py", line 230, in fromString
    return Pynliner(log).from_string(string).run()

  File "pynliner/**init**.py", line 91, in run
    return self._get_output()

  File "pynliner/**init**.py", line 211, in _get_output
    self.output = unicode(str(self.soup))



Discussion:

Resolving patch:
diff --git a/sentry/plugins/sentry_mail/models.py b/sentry/plugins/sentry_mail/models.py
--- a/sentry/plugins/sentry_mail/models.py
+++ b/sentry/plugins/sentry_mail/models.py
@@ -125,7 +125,7 @@ def notify_users(self, group, event, fail_silently=False):
                 continue
             interface_list.append((interface.get_title(), body))
 
-        subject = '[%s] %s: %s' % (project.name.encode('utf-8'), event.get_level_display().upper(), event.error().encode('utf-8').split('\n')[0])
+        subject = '[%s] %s: %s' % (project.name.encode('utf-8'), event.get_level_display().upper().encode('utf-8'), event.error().encode('utf-8').split('\n')[0])
 
         link = '%s/%s/group/%d/' % (settings.URL_PREFIX, group.project.slug, group.id)
 


Test patch:
diff --git a/tests/sentry/plugins/mail/tests.py b/tests/sentry/plugins/mail/tests.py
--- a/tests/sentry/plugins/mail/tests.py
+++ b/tests/sentry/plugins/mail/tests.py
@@ -106,6 +106,33 @@ def test_notify_users_renders_interfaces_with_utf8(self, _send_mail):
         stacktrace.get_title.assert_called_once_with()
         stacktrace.to_string.assert_called_once_with(event)
 
+    @mock.patch('sentry.plugins.sentry_mail.models.MailProcessor._send_mail')
+    def test_notify_users_renders_interfaces_with_utf8_fix_issue_422(self, _send_mail):
+        group = Group()
+        group.first_seen = datetime.datetime.now()
+        group.last_seen = group.first_seen
+        group.id = 2
+        group.project_id = 1
+
+        stacktrace = Mock(spec=Stacktrace)
+        stacktrace.to_string.return_value = u'רונית מגן'
+        stacktrace.get_title.return_value = 'Stacktrace'
+
+        event = Event()
+        event.group = group
+        event.message = 'Soubor ji\xc5\xbe existuje'
+        event.logger = 'root'
+        event.site = None
+        event.interfaces = {'sentry.interfaces.Stacktrace': stacktrace}
+
+        with self.Settings(SENTRY_URL_PREFIX='http://example.com'):
+            p = MailProcessor(send_to=['foo@example.com'])
+            p.notify_users(group, event)
+
+        stacktrace.get_title.assert_called_once_with()
+        stacktrace.to_string.assert_called_once_with(event)
+
+
     @mock.patch('sentry.plugins.sentry_mail.models.MailProcessor._send_mail')
     def test_notify_users_does_email(self, _send_mail):
         project = Project(id=1, name='Project Name')