Ejemplo n.º 1
0
func inspect_part(ob gmime.Object, level int) {
	{
		fmt.Printf("=================== PART HEADER =======================\n")
		fmt.Printf("%v\n", ob.Headers())
		fmt.Printf("================= END PART HEADER =====================\n")
	}

	fmt.Printf("=================== PART BODY =======================\n")
	if mp, ok := ob.(gmime.Multipart); ok {
		n := mp.Count()
		fmt.Printf("Object type: gmime.Multipart, %d items\n", n)
		for i := 0; i < n; i++ {
			subpart := mp.GetPart(i)
			fmt.Printf("%d >>> SUBPART: %d\n", level, i)
			inspect_part(subpart, level+1)
		}
	} else if mp, ok := ob.(gmime.MessagePart); ok {
		fmt.Printf("Object type: gmime.MessagePart\n")
		ostream := gmime.NewMemStream()
		mp.Message().WriteToStream(ostream)
		defer inspectAndClose(ostream)
	} else if p, ok := ob.(gmime.Part); ok {
		fmt.Printf("Object type: gmime.Part\n")
		ostream := gmime.NewMemStream()
		defer inspectAndClose(ostream)
		dataWrapper := p.ContentObject()
		dataWrapper.WriteToStream(ostream)
	}
	fmt.Printf("=================== END OF PART BODY =======================\n")
}
Ejemplo n.º 2
0
func (s *AbstractStreamTestSuite) TestGenericStream() {
	buffer := s.buffer
	stream := s.stream

	assert.Equal(s.T(), stream.Length(), len(buffer))
	length, word := stream.Read((int64)(5))
	assert.Equal(s.T(), 5, length)
	assert.Equal(s.T(), "hello", (string)(word))
	assert.Equal(s.T(), 5, stream.Tell())
	stream.Seek(5+2, os.SEEK_SET)
	assert.Equal(s.T(), 5+2, stream.Tell())
	assert.False(s.T(), stream.Eos())
	capitalW := [1]byte{(byte)('W')}
	stream.WriteBlock(([]byte)(capitalW[0:1]), (int64)(1))
	stream.Reset()
	length, word = stream.Read((int64)(len(buffer) + 1))
	assert.Equal(s.T(), len(buffer), length)
	assert.Equal(s.T(), "hello, World!", (string)(word))
	stream.Seek(0, os.SEEK_END)
	// XXX The File Stream doesn't know it's at EOF until another read is tried
	stream.Read((int64)(1))
	assert.True(s.T(), stream.Eos())
	stream.Reset()
	subStream := stream.SubStream(0, 5)
	subString := "y"
	res := subStream.WriteString(subString)
	assert.Equal(s.T(), 1, res)
	subStream.Seek(-1, os.SEEK_CUR)
	length, word = subStream.Read((int64)(4))
	assert.Equal(s.T(), "yell", string(word))
	outStream := gmime.NewMemStream()
	stream.WriteToStream(outStream)
	assert.Equal(s.T(), "yello, World!", string(outStream.Bytes()))
	outStream.Close()
}
Ejemplo n.º 3
0
func sizeAndHashOf(p gmime.Part) (int, string) {
	dataWrapper := p.ContentObject()
	memStream := gmime.NewMemStream()
	c := dataWrapper.WriteToStream(memStream)
	memStream.Flush()
	data := memStream.Bytes()
	hasher := md5.New()
	hasher.Write(data)
	hashString := hex.EncodeToString(hasher.Sum(nil))
	return int(c), hashString
}