Ejemplo n.º 1
0
func TestFileStreamWithPathTestSuite(t *testing.T) {
	s := "hello, world!"
	tempFilepath := path.Join(os.TempDir(), "hello-gmime.txt")

	{
		err := ioutil.WriteFile(tempFilepath, []byte(s), 0644)
		assert.NoError(t, err)
		defer os.Remove(tempFilepath)

		rfs := gmime.NewFileStreamForPath(tempFilepath, "r")
		l := rfs.Length()
		l2, r := rfs.Read(l)
		assert.Equal(t, l, len(s))
		assert.Equal(t, l, l2)
		assert.Equal(t, s, r)
	}

	{
		wfs := gmime.NewFileStreamForPath(tempFilepath, "w")
		defer os.Remove(tempFilepath)
		b := []byte(s)
		l := wfs.Write(b)
		assert.Equal(t, l, len(b))
		wfs.Close()

		r, err := ioutil.ReadFile(tempFilepath)
		assert.NoError(t, err)
		assert.Equal(t, r, s)
	}
	{
		wfs := gmime.NewFileStreamForPath(tempFilepath, "w")
		defer os.Remove(tempFilepath)
		l := wfs.WriteString(s)
		assert.Equal(t, l, len(s))
		wfs.Close()

		r, err := ioutil.ReadFile(tempFilepath)
		assert.NoError(t, err)
		assert.Equal(t, r, s)
	}
}
Ejemplo n.º 2
0
func main() {
	flag.Parse()
	if file_name == "" {
		panic("no filename given")
	}

	fs := gmime.NewFileStreamForPath(file_name, "r")
	if fs == nil {
		panic("can't open " + file_name)
	}

	parser := gmime.NewParserWithStream(fs)
	parser.SetScanFrom(scan_from)
	message := parser.ConstructMessage()
	if message != nil {
		msgid, ok := message.MessageId()
		fmt.Printf("Inspecting %s\n: message.MessageId() == \"%v\", %v\n", file_name, msgid, ok)
		inspect_message(message)
	}
}