-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_mboxdetecttype_test.go
50 lines (43 loc) · 1.14 KB
/
example_mboxdetecttype_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package mbox_test
import (
"bytes"
"fmt"
"github.com/tvanriper/mbox"
)
// Imagine this is a file on your filesystem instead of a variable in your code.
const mboxrd2 string = `From [email protected] Mon Jul 04 14:23:45 2022
From: [email protected]
Subject: To interpretation
>From all of us, to all of you, be happy!
From [email protected] Mon Jul 04 15:02:15 2022
From: [email protected]
Subject: Bestest offer in the universe!!11!!
You won't believe these prices!
>From 1 cent to 11 cents, we carry the least expensive
line of jets this side of the Gobi Desert!
`
func ExampleDetectType() {
// Imagine you used os.Open instead of bytes.NewBuffer here.
reader := bytes.NewReader([]byte(mboxrd2))
mbType, err := mbox.DetectType(reader)
if err != nil {
fmt.Printf("failed to detect mbox type: %s\n", err)
return
}
switch mbType {
case mbox.MBOXO:
fmt.Println("MBOXO")
case mbox.MBOXRD:
fmt.Println("MBOXRD")
case mbox.MBOXCL:
fmt.Println("MBOXCL")
case mbox.MBOXCL2:
fmt.Println("MBOXCL2")
default:
fmt.Println("Unknown")
}
// Output:
// MBOXRD
}