func TestReadsEmailWithCorrectSignature(t *testing.T) {
	e := email(t, "correct_sig")

	assert.Len(t, e.Fragments, 2)
	assert.Equal(t, []bool{false, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, true}, signatures(e.Fragments))
	assert.Equal(t, []bool{false, true}, hiddens(e.Fragments))
	assert.Regexp(t, regexp.MustCompile("^-- \nrick"), e.Fragments[1].String())
}
func TestMultipleOn(t *testing.T) {
	e := email(t, "greedy_on")

	assert.Regexp(t, regexp.MustCompile(`(?m)^On your remote host`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^On 9 Jan 2014`), e.Fragments[1].String())
	assert.Equal(t, []bool{false, true, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, false, false}, signatures(e.Fragments))
	assert.Equal(t, []bool{false, true, true}, hiddens(e.Fragments))

}
func TestReadsTopPost(t *testing.T) {
	e := email(t, "email_1_3")

	assert.Len(t, e.Fragments, 5)
	assert.Equal(t, []bool{false, false, true, false, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, true, true, true, true}, hiddens(e.Fragments))
	assert.Equal(t, []bool{false, true, false, false, true}, signatures(e.Fragments))
	assert.Regexp(t, regexp.MustCompile(`^Oh thanks.\n\nHaving`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`^-A`), e.Fragments[1].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^On [^\:]+\:`), e.Fragments[2].String())
	assert.Regexp(t, regexp.MustCompile(`^_`), e.Fragments[4].String())
}
func TestReadsBottomPost(t *testing.T) {
	e := email(t, "email_1_2")

	assert.Len(t, e.Fragments, 6)
	assert.Equal(t, []bool{false, true, false, true, false, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, false, false, false, false, true}, signatures(e.Fragments))
	assert.Equal(t, []bool{false, false, false, true, true, true}, hiddens(e.Fragments))
	assert.Equal(t, "Hi,", e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`^On [^\:]+\:`), e.Fragments[1].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^You can list`), e.Fragments[2].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^> `), e.Fragments[3].String())
	assert.Regexp(t, regexp.MustCompile(`^_`), e.Fragments[5].String())
}
func TestReadsInlineReplies(t *testing.T) {
	e := email(t, "email_1_8")

	assert.Len(t, e.Fragments, 7)
	assert.Equal(t, []bool{true, false, true, false, true, false, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, false, false, false, false, false, true}, signatures(e.Fragments))
	assert.Equal(t, []bool{false, false, false, false, true, true, true}, hiddens(e.Fragments))
	assert.Regexp(t, regexp.MustCompile(`^On [^\:]+\:`), e.Fragments[0].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^I will reply`), e.Fragments[1].String())
	assert.Regexp(t, regexp.MustCompile(`okay?`), e.Fragments[2].String())
	assert.Regexp(t, regexp.MustCompile(`(?m)^and under this.`), e.Fragments[3].String())
	assert.Regexp(t, regexp.MustCompile(`inline`), e.Fragments[4].String())
	assert.Equal(t, "\n", e.Fragments[5].String())
	assert.Equal(t, e.Fragments[6].String(), "--\nHey there, this is my signature\n")
}
func TestReadsSimpleBody(t *testing.T) {
	e := email(t, "email_1_1")

	assert.Len(t, e.Fragments, 3)
	assert.Equal(t, []bool{false, false, false}, quoteds(e.Fragments))
	assert.Equal(t, []bool{false, true, true}, signatures(e.Fragments))
	assert.Equal(t, []bool{false, true, true}, hiddens(e.Fragments))
	assert.Equal(t, `Hi folks

What is the best way to clear a Riak bucket of all key, values after
running a test?
I am currently using the Java HTTP API.
`, e.Fragments[0].String())
	assert.Equal(t, "-Abhishek Kona\n\n", e.Fragments[1].String())
}
func TestRetainsBullets(t *testing.T) {
	b := emailBody(t, "email_bullets")

	reply, err := ParseReply(b)
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, "test 2 this should list second\n\nand have spaces\n\nand retain this formatting\n\n\n   - how about bullets\n   - and another", reply)
}
func TestDoNotParseOutSendFromInRegularSentence(t *testing.T) {
	b := emailBody(t, "email_sent_from_my_not_signature")

	reply, err := ParseReply(b)
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, "Here is another email\n\nSent from my desk, is much easier then my mobile phone.", reply)
}
func TestParseOutSendFromMultiwordMobileDevice(t *testing.T) {
	b := emailBody(t, "email_multi_word_sent_from_my_mobile_device")

	reply, err := ParseReply(b)
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, "Here is another email", reply)
}
Beispiel #10
0
func TestParseOutSentFromBlackberry(t *testing.T) {
	b := emailBody(t, "email_BlackBerry")

	reply, err := ParseReply(b)
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, "Here is another email", reply)
}
Beispiel #11
0
func TestParseOutJustTopForOutlookWithReplyDirectlyAboveLine(t *testing.T) {
	b := emailBody(t, "email_2_2")

	reply, err := ParseReply(b)
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, "Outlook with a reply directly above line", reply)
}
Beispiel #12
0
func TestParseOutJustTopForOutlookReply(t *testing.T) {
	b := emailBody(t, "email_2_1")

	reply, err := ParseReply(b)
	if err != nil {
		t.Error(err)
	}
	assert.Equal(t, "Outlook with a reply", reply)
}
Beispiel #13
0
func TestReturnsOnlyTheVisibleFragmentsAsAString(t *testing.T) {
	e := email(t, "email_2_1")

	var visibleStrings []string
	for _, fragment := range e.Fragments {
		if !fragment.Hidden {
			visibleStrings = append(visibleStrings, fragment.String())
		}
	}
	assert.Equal(t, strings.TrimRightFunc(strings.Join(visibleStrings, "\n"), unicode.IsSpace), e.VisibleText())
}
Beispiel #14
0
func TestParseReply(t *testing.T) {
	b := emailBody(t, "email_1_2")

	reply, err := ParseReply(b)
	if err != nil {
		t.Error(err)
	}

	e, err := Read(b)
	if err != nil {
		t.Fatal(err)
	}

	assert.Equal(t, e.VisibleText(), reply)
}