sj26 / mailcatcher

Catches mail and serves it through a dream.
http://mailcatcher.me
MIT License
6.31k stars 578 forks source link

Problem with base64 message #308

Closed jbouzekri closed 8 years ago

jbouzekri commented 8 years ago

Hi,

This is the source of the mail I am receiving in mailcatcher :

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Subject: Tracker Kid - Reaching call usage limit

From: Ma p'tite balise <alert@maptitebalise.com>
To: Test Test <test@weenect.com>

Qm9uam91ciBUZXN0IFRlc3QsCgpWb3VzIMOqdGVzIHN1ciBsZSBwb2ludCBkJ2F0dGVpbmRyZSBs
YSBsaW1pdGUgZCd1dGlsaXNhdGlvbiBkZSBsYSBmb25jdGlvbiBTT1MgZGUgdm90cmUgYmFsaXNl
IFRyYWNrZXIgS2lkLgoKVm91cyBhdmV6IGTDqWrDoCBhcHBlbMOpIHBvdXIgODo0OC4KCkxhIGxp
bWl0ZSBlc3QgcG9zaXRpb25uw6llIMOgIDEwLgoKTGUgY29tcHRldXIgZXN0IHLDqWluaXRpYWxp
c8OpIHRvdXMgbGVzIHByZW1pZXJzIGR1IG1vaXMuCgpDb3JkaWFsZW1lbnQsCgpUZWFtIFdlZW5l
Y3QK

However when I open the plain text tab, I get this :

�&1�m�כjX�y�^�ٚ�حy���ǜ�d�M�-M�-��-���y�\�d&����W"FW7BFW7B���f�W2:�FW27W"�R���BBvGFV��G&R�Ɩ֗FRBwWF�Ɨ6F���FR�f��7F���4�2FRf�G&R&Ɨ6RG&6�W"��Bࠥf�W2fW�L:��:V�:��W"��C�ࠤ�Ɩ֗FRW7B�6�F����:�R:ࠤ�R6��FWW"W7B,:����F�Ɨ<:�F�W2�W2&V֖W'2GR���2ࠤ6�&F��V�V�B���FV�vVV�V7

But the base64 in the source seems to be okay :

>>> base64mail = """Qm9uam91ciBUZXN0IFRlc3QsCgpWb3VzIMOqdGVzIHN1ciBsZSBwb2ludCBkJ2F0dGVpbmRyZSBs
... YSBsaW1pdGUgZCd1dGlsaXNhdGlvbiBkZSBsYSBmb25jdGlvbiBTT1MgZGUgdm90cmUgYmFsaXNl
... IFRyYWNrZXIgS2lkLgoKVm91cyBhdmV6IGTDqWrDoCBhcHBlbMOpIHBvdXIgODo0OC4KCkxhIGxp
... bWl0ZSBlc3QgcG9zaXRpb25uw6llIMOgIDEwLgoKTGUgY29tcHRldXIgZXN0IHLDqWluaXRpYWxp
... c8OpIHRvdXMgbGVzIHByZW1pZXJzIGR1IG1vaXMuCgpDb3JkaWFsZW1lbnQsCgpUZWFtIFdlZW5l
... Y3QK"""
>>> base64mail = base64mail.replace('\n', '').replace('\r', '').replace(' ', '')
>>> print base64.b64decode(base64mail).decode('utf-8')
Bonjour Test Test,

Vous êtes sur le point d'atteindre la limite d'utilisation de la fonction SOS de votre balise Tracker Kid.

Vous avez déjà appelé pour 8:48.

La limite est positionnée à 10.

Le compteur est réinitialisé tous les premiers du mois.

Cordialement,

Team Weenect
sj26 commented 8 years ago

Oh no! I'm sorry that's not working for you.

I've just tried this myself locally and I get the correct result:

screenshot 2016-09-15 10 17 28

Could you confirm a few details for me?

This smells like a ruby version issue. Older ruby wasn't great at encodings.

jbouzekri commented 8 years ago

@sj26 thanks for your quick answer and your detailed tests. I am using the docker image schickling/mailcatcher.

jobou@jonathan:~$ docker run -ti schickling/mailcatcher /bin/bash
root@c98f455f7cf0:/# mailcatcher --version
mailcatcher 0.6.1
root@c98f455f7cf0:/# ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
root@c98f455f7cf0:/# gem list

*** LOCAL GEMS ***

activesupport (4.2.5)
daemons (1.2.3)
eventmachine (1.0.5)
i18n (0.7.0)
json (1.8.3)
mail (2.6.3)
mailcatcher (0.6.1)
mime-types (2.99)
minitest (5.8.3)
rack (1.6.4)
rack-protection (1.5.3)
sinatra (1.4.6)
skinny (0.2.3)
sqlite3 (1.3.11)
thin (1.5.1)
thread_safe (0.3.5)
tilt (2.0.1)
tzinfo (1.2.2)
sj26 commented 8 years ago

@jbouzekri that's an older version of mailcatcher, and it looks like the docker image has moved on. Have you tried doing docker pull schickling/mailcatcher?

$ docker run --rm -it schickling/mailcatcher mailcatcher --version
mailcatcher 0.6.5
jbouzekri commented 8 years ago

Just tried after having done a docker pull and I have the same issue.

This is the result of the command you asked :

root@5a1e39abc5f1:/# mailcatcher --version
mailcatcher 0.6.5
root@5a1e39abc5f1:/# ruby --version
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-linux]
root@5a1e39abc5f1:/# gem list

*** LOCAL GEMS ***

bigdecimal (default: 1.2.6)
bundler (1.12.5)
daemons (1.2.4)
eventmachine (1.0.9.1)
io-console (default: 0.4.3)
json (default: 1.8.1)
mail (2.6.4)
mailcatcher (0.6.5)
mime-types (3.1)
mime-types-data (3.2016.0521)
minitest (5.4.3)
power_assert (0.2.2)
psych (default: 2.0.8)
rack (1.6.4)
rack-protection (1.5.3)
rake (default: 10.4.2)
rdoc (default: 4.2.0)
rubygems-update (2.6.6)
sinatra (1.4.7)
skinny (0.2.4)
sqlite3 (1.3.11)
test-unit (3.0.8)
thin (1.5.1)
tilt (2.0.5)
jbouzekri commented 8 years ago

I am closing this issue because I found out what went wrong.

If you look into my Subject header, you will see that there is a carriage return at the end. So the From header does not stuck to it. When I trim my subject to remove the carriage return, everything works correctly.

Thanks for your help and this amazing development tools (I am especially in love with the docker container. Easy to install, easy to run)