Ejemplo n.º 1
0
func (s *MySuite) TestRemoveMailThreadWithSingleReference(c *C) {

	session, err := mgo.Dial("localhost")
	c.Assert(err, IsNil)
	defer session.Close()
	coll := session.DB(mailBox).C(threadsCollection)

	var mail mail.Mail
	mail.Init()
	mail.From = bson.NewObjectId()
	mail.Subject = "Hello world"
	mail.Mailtext = "Long mail text"
	mailThreadId, errr := CreateNewMailThread(coll, &mail)
	c.Assert(errr, Equals, true)
	retval := DeleteMailThread(coll, mailThreadId)

	c.Assert(retval, Equals, true)
	_, err = findMailThread(coll, mailThreadId)
	c.Assert(err, NotNil)

}
Ejemplo n.º 2
0
func (s *MySuite) TestCreateEmptyMailThread(c *C) {

	session, err := mgo.Dial("localhost")
	c.Assert(err, IsNil)
	defer session.Close()
	coll := session.DB(mailBox).C(threadsCollection)

	var mail mail.Mail
	mail.Init()
	threadId, retval := CreateNewMailThread(coll, &mail)
	c.Assert(retval, Equals, true)

	var mailThread MailThread
	err = coll.FindId(threadId).One(&mailThread)
	c.Assert(err, IsNil)
	c.Assert(mailThread.Id, Equals, threadId)
	c.Assert(mailThread.ReferenceCount, Equals, 0)
	c.Assert(len(mailThread.Mails), Equals, 1)

	// TODO figure out why nsec is not same :(
	//c.Assert(mailThread.Mails[0], DeepEquals, mail)
}
Ejemplo n.º 3
0
// Create a new Mail thread
func CreateNewMailThread(s *mgo.Collection, mail *mail.Mail) (bson.ObjectId, bool) {

	var newMailThread MailThread

	newMailThread.Init()
	newMailThread.ReferenceCount = mail.GetReferenceCount()

	newMailThread.Mails = append(newMailThread.Mails, *mail)

	err := s.Insert(newMailThread)
	if err != nil {
		// TODO do a logging to track everything
		panic("Failed to insert the mail" + err.Error())
		return newMailThread.Id, false
	}
	return newMailThread.Id, true
}