package imap import ( "strings" "testing" ) func TestDecodeBareBase64IfNeeded_samsungMessage(t *testing.T) { const encoded = "U0FNU1VORwpSw6lzZXJ2w6kgYXV4IHByb2Zlc3Npb25uZWxzCgrigIoKVm9zIMOpcXVpcGVzIG9u\r\n" + "dCBiZXNvaW4KZGUgc29sdXRpb25zIG1vYmlsZXMKZXQgcm9idXN0ZXMuCgpTYW1zdW5nIFBybyBy\r\n" + "w6lwb25kIGF1eCBtw6l0aWVycyBkZSBsYSBjb25zdHJ1" decoded := decodeBareBase64IfNeeded(encoded) if decoded == encoded { t.Fatal("expected base64 decode") } if !strings.HasPrefix(decoded, "SAMSUNG") { t.Fatalf("decoded = %q", decoded) } if !strings.Contains(decoded, "professionnels") { t.Fatalf("decoded = %q, want utf-8 text", decoded) } } func TestDecodeBareQuotedPrintableIfNeeded_frenchMarketing(t *testing.T) { const qp = "Hello = Eliott,\n\nNous pouvons faire appara=C3=AEtre votre marque en premi=C3=A8re =\n" + " position dans les Google Suggests" decoded := decodeBareQuotedPrintableIfNeeded(qp) if decoded == qp { t.Fatal("expected quoted-printable decode") } if !strings.Contains(decoded, "apparaître") { t.Fatalf("decoded = %q, want apparaître", decoded) } if strings.Contains(decoded, "=C3=") { t.Fatalf("still contains qp escapes: %q", decoded) } } func TestRepairStoredBodies_quotedPrintableHTML(t *testing.T) { const qpHTML = `
Hello Eliott, Nous pouvons faire apparaître votre marque.