Commit be2cb4d
committed
Base64 encode file attachments
By default ActionMailer tries to encode any file attachments in Base64.
We've seen a problem in production where this encoding fails with an
error 'invalid byte sequence in UTF-8'. We think this happens when a
binary file has been uploaded with a text file extension, so the
ActionMailer logic expects a text file but receives binary characters.
To fix this, we can encode the files in Base64 ourselves before passing
them to ActionMailer, which bypasses the failing logic. This allows us
to pass these disguised binary files to ActionMailer without errors.
Other files should be unaffected and the resulting emails should be
otherwise identical.1 parent 6bff018 commit be2cb4d
3 files changed
Lines changed: 27 additions & 1 deletion
File tree
- app/mailers
- spec
- features
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
87 | 110 | | |
88 | 111 | | |
89 | 112 | | |
| |||
Binary file not shown.
0 commit comments