-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subject mime decode functions and test
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package store | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestSubjectMatch(t *testing.T) { | ||
// Auto detect subject text encoding and decode | ||
|
||
//log := mlog.New("search", nil) | ||
|
||
originalSubject := `テストテキスト Abc 123...` | ||
asciiSubject := "test text Abc 123..." | ||
|
||
encodedSubjectUTF8 := `=?UTF-8?B?44OG44K544OI44OG44Kt44K544OIIEFiYyAxMjMuLi4=?=` | ||
encodedSubjectISO2022 := `=?iso-2022-jp?B?GyRCJUYlOSVIJUYlLSU5JUgbKEIgQWJjIDEyMy4uLg==?=` | ||
encodedSubjectUTF8 = encodedSubjectUTF8 + " \n " + encodedSubjectUTF8 | ||
encodedSubjectISO2022 = encodedSubjectISO2022 + " \n " + encodedSubjectISO2022 | ||
originalSubject = originalSubject + originalSubject | ||
|
||
encodedTexts := map[string]string{encodedSubjectUTF8: originalSubject, encodedSubjectISO2022: originalSubject, asciiSubject: asciiSubject} | ||
|
||
for encodedSubject, originalSubject := range encodedTexts { | ||
|
||
// Autodetect & decode | ||
decodedSubject, err := decodeRFC2047(encodedSubject) | ||
|
||
fmt.Printf("decoded text:%s\n", decodedSubject) | ||
if err != nil { | ||
t.Fatalf("Decode error: %v", err) | ||
} | ||
|
||
if originalSubject != decodedSubject { | ||
t.Fatalf("Decode mismatch %s != %s", originalSubject, decodedSubject) | ||
} | ||
} | ||
} |