-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.go
More file actions
67 lines (59 loc) · 1.27 KB
/
article.go
File metadata and controls
67 lines (59 loc) · 1.27 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package nntp
import (
"io"
"net/textproto"
"strconv"
"strings"
"time"
)
type ArticleOverview struct {
ArticleId int
Subject string
From string
Date time.Time
MessageId string
References []string
Bytes int
Lines int
}
type Article struct {
Header textproto.MIMEHeader
Body io.Reader
// Number of bytes in the article body (used by OVER/XOVER)
Bytes int
// Number of lines in the article body (used by OVER/XOVER)
Lines int
}
// MessageID provides convenient access to the article's Message ID.
func (a *Article) MessageID() string {
return a.Header.Get("Message-Id")
}
func overviewFromLine(line string) (o *ArticleOverview, err error) {
params := strings.SplitN(line, "\t", 9)
if len(params) < 8 {
return nil, textproto.ProtocolError("Unexpected FMT: " + line)
}
var a, b, l int
var d time.Time
a, err = strconv.Atoi(params[0])
b, err = strconv.Atoi(params[6])
l, err = strconv.Atoi(params[7])
if err != nil {
return nil, err
}
d, err = parseDate(params[3])
if err != nil {
d = time.Time{}
}
o = &ArticleOverview{
ArticleId: a,
Subject: params[1],
From: params[2],
Date: d,
MessageId: params[4],
References: strings.Split(params[5], " "),
Bytes: b,
Lines: l,
}
return o, nil
}