package main_test import ( . "github.com/carlostrub/sisyphus" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("Main", func() { Context("Maildir", func() { It("Create a slice of mail keys", func() { result, err := Index("test/Maildir") Ω(err).ShouldNot(HaveOccurred()) Ω(result).Should(Equal( []*Mail{ { Key: "1488230510.M141612P8565.mail.carlostrub.ch,S=5978,W=6119", Subject: nil, Body: nil, Junk: false, }, { Key: "1488181583.M633084P4781.mail.carlostrub.ch,S=708375,W=720014", Subject: nil, Body: nil, Junk: true, }, { Key: "1488226337.M327824P8269.mail.carlostrub.ch,S=8044,W=8167", Subject: nil, Body: nil, Junk: true, }, { Key: "1488226337.M327825P8269.mail.carlostrub.ch,S=802286,W=812785", Subject: nil, Body: nil, Junk: true, }, { Key: "1488228352.M339670P8269.mail.carlostrub.ch,S=12659,W=12782", Subject: nil, Body: nil, Junk: true, }, { Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730", Subject: nil, Body: nil, Junk: true, }, { Key: "1488226337.M327833P8269.mail.carlostrub.ch,S=6960,W=7161", Subject: nil, Body: nil, Junk: true, }, })) }) It("Fail if Maildir does not exist", func() { _, err := Index("test/DOESNOTEXIST") Ω(err).Should(HaveOccurred()) }) }) Context("Mail", func() { It("Load mail content into struct", func() { m := Mail{ Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730", Subject: nil, Body: nil, Junk: true, } err := m.Load("test/Maildir" + "/.Junk") Ω(err).ShouldNot(HaveOccurred()) subject := "hello" body := "This is a multi-part message in MIME format. ------=_NextPart_000_0032_01D2912F.05324BC6 Content-Type: text/plain; \tcharset=\"cp-850\" Content-Transfer-Encoding: quoted-printable Dear cs, We are looking for employees working remotely. My name is Kari, I am the personnel manager of a large International company. Most of the work you can do from home, that is, at a distance. Salary is $2000-$5300. If you are interested in this offer, please visit Our Site Best regards! ------=_NextPart_000_0032_01D2912F.05324BC6 Content-Type: text/html; \tcharset=\"cp-850\" Content-Transfer-Encoding: quoted-printable

Dear cs,

We are looking for employees working remotely.

My name is Kari, I am the personnel manager of a large International company.
Most of the work you can do from home, that is, at a distance.
Salary is $2000-$5300.

If you are interested in this offer, please visit Our Site

Best regards!

------=_NextPart_000_0032_01D2912F.05324BC6-- " Ω(m).Should(Equal( Mail{ Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730", Subject: &subject, Body: &body, Junk: true, })) }) It("Fail if Subject has content already", func() { s := "test" m := Mail{ Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730", Subject: &s, Body: nil, Junk: true, } err := m.Load("test/Maildir" + "/.Junk") Ω(err).Should(HaveOccurred()) }) It("Fail if Body has content already", func() { b := "test" m := Mail{ Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730", Subject: nil, Body: &b, Junk: true, } err := m.Load("test/Maildir" + "/.Junk") Ω(err).Should(HaveOccurred()) }) It("Clean mail content", func() { subject := "Hello" body := "This is a multi-part message in MIME format. ------=_NextPart_000_0032_01D2912F.05324BC6 Content-Type: text/plain; \tcharset=\"cp-850\" Content-Transfer-Encoding: quoted-printable Dear cs, We are looking for employees working remotely. My name is Kari, I am the personnel manager of a large International company. Most of the work you can do from home, that is, at a distance. Salary is $2000-$5300. If you are interested in this offer, please visit Our Site Best regards! ------=_NextPart_000_0032_01D2912F.05324BC6 Content-Type: text/html; \tcharset=\"cp-850\" Content-Transfer-Encoding: quoted-printable

Dear cs,

We are looking for employees working remotely.

My name is Kari, I am the personnel manager of a large International company.
Most of the work you can do from home, that is, at a distance.
Salary is $2000-$5300.

If you are interested in this offer, please visit Our Site

Best regards!

------=_NextPart_000_0032_01D2912F.05324BC6-- " m := Mail{ Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730", Subject: &subject, Body: &body, Junk: true, } err := m.Clean() Ω(err).ShouldNot(HaveOccurred()) subjectOutput := "hello" bodyOutput := "This is a multi-part message in MIME format. ------=_NextPart_000_0032_01D2912F.05324BC6 Content-Type: text/plain; \tcharset=\"cp-850\" Content-Transfer-Encoding: quoted-printable Dear cs, We are looking for employees working remotely. My name is Kari, I am the personnel manager of a large International company. Most of the work you can do from home, that is, at a distance. Salary is $2000-$5300. If you are interested in this offer, please visit Our Site Best regards! ------=_NextPart_000_0032_01D2912F.05324BC6 Content-Type: text/html; \tcharset=\"cp-850\" Content-Transfer-Encoding: quoted-printable

Dear cs,

We are looking for employees working remotely.

My name is Kari, I am the personnel manager of a large International company.
Most of the work you can do from home, that is, at a distance.
Salary is $2000-$5300.

If you are interested in this offer, please visit Our Site

Best regards!

------=_NextPart_000_0032_01D2912F.05324BC6-- " Ω(m).Should(Equal( Mail{ Key: "1488226337.M327822P8269.mail.carlostrub.ch,S=3620,W=3730", Subject: &subjectOutput, Body: &bodyOutput, Junk: true, })) }) }) })