Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate the last char in Plain text #32

Open
arthtux opened this issue Apr 30, 2018 · 3 comments
Open

Duplicate the last char in Plain text #32

arthtux opened this issue Apr 30, 2018 · 3 comments

Comments

@arthtux
Copy link

arthtux commented Apr 30, 2018

I have a duplicate char in the plain text.

On Plain text i Have

BLACKLISTED WAKE UP SMS SENT (+33606060606) : Voici le numéro de confirmation de votre téléphone : 778626. Merci..

But in source I have

BLACKLISTED WAKE UP SMS SENT (+33606060606) : Voici le num=C3=A9ro de con= firmation de votre t=C3=A9l=C3=A9phone : 778626. Merci.=

Maybe the problem is in https://github.com/mailhog/MailHog-UI/blob/master/assets/js/strutil.js#L280

@scollon42
Copy link

scollon42 commented Apr 30, 2018

Seems that

function decodeQuotedPrintableHelper

return NaN for the last prefix = after Merci.
and when the result go to

function convertBytesToUnicodeCodePoints

it will duplicate the previous bytes while where there is a NaN
for exemple

var ret = decodeQuotedPrintableHelper("BLACKLISTED WAKE UP SMS SENT (+33612345678) : Votre code de v=C3=A9rifica=tion Koolicar : 140035=", "=")

ret /*=> [66, 76, 65, 67, 75, 76, 73, 83, 84, 69, 68, 32, 87, 65, 75, 69, 32, 85, 80, 32, 83, 77, 83, 32, 83, 69, 78, 84, 32, 40, 43, 51, 51, 54, 49, 50, 51, 52, 53, 54, 55, 56, 41, 32, 58, 32, 86, 111, 116, 114, 101, 32, 99, 111, 100, 101, 32, 100, 101, 32, 118, 195, 169, 114, 105, 102, 105, 99, 97, NaN, 111, 110, 32, 75, 111, 111, 108, 105, 99, 97, 114, 32, 58, 32, 49, 52, 48, 48, 51, 53, NaN] */

convertBytesToUnicodeCodePoints(ret, "UTF8") /*=> [66, 76, 65, 67, 75, 76, 73, 83, 84, 69, 68, 32, 87, 65, 75, 69, 32, 85, 80, 32, 83, 77, 83, 32, 83, 69, 78, 84, 32, 40, 43, 51, 51, 54, 49, 50, 51, 52, 53, 54, 55, 56, 41, 32, 58, 32, 86, 111, 116, 114, 101, 32, 99, 111, 100, 101, 32, 100, 101, 32, 118, 233, 114, 105, 102, 105, 99, 97, 97, 111, 110, 32, 75, 111, 111, 108, 105, 99, 97, 114, 32, 58, 32, 49, 52, 48, 48, 51, 53, 53] */

I think for this last char in decodeQuotedPrintableHelper function there is an edge case.
here prefix for quoted printable is = the function will go through this condition :

if (str.charAt(i) == prefix ) {
  ret= decoded_bytes.push(parseInt(str.substr(i + 1, 2), 16));
  i += 3;
}

but here :

parseInt(str.substr(i + 1, 2), 16)
/* i + 1 == str.length  so str.substr will return an empty string and parseInt will return NaN */

This can fix the NaN case :

function decodeQuotedPrintableHelper(str, prefix) {
  var decoded_bytes = [];
  for (var i = 0; i < str.length;) {
    if (str.charAt(i) == prefix) {

     // here we check if it's not the end of the str
      if (i + 1 < str.length) {
      	decoded_bytes.push(parseInt(str.substr(i + 1, 2), 16));
      }

      i += 3;
    } else {
      decoded_bytes.push(str.charCodeAt(i));
	  ++i;
    }
  }
  return decoded_bytes;
}

hope this can help 😃

@scollon42
Copy link

scollon42 commented May 9, 2018

it should be fixed by this Pull Request: #33
I did a quick fix so don't hesitate to challenge it and review the code 😄

@TheMatrix97
Copy link

I have the same issue, using encoding cp1252.
plain text: "enlla seggent"
Source code: "l'enlla=E7 seg=FCent"
@scollon42 How could I include this modification to a running docker container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants