gay bullshit
This commit is contained in:
parent
99a3403ed8
commit
666549e1e4
@ -6,29 +6,35 @@ import (
|
||||
)
|
||||
|
||||
type LineWriter struct {
|
||||
w io.Writer
|
||||
Left int64
|
||||
w io.Writer
|
||||
limit int
|
||||
}
|
||||
|
||||
func NewLineWriter(w io.Writer, limit int64) *LineWriter {
|
||||
func NewLineWriter(w io.Writer, limit int) *LineWriter {
|
||||
return &LineWriter{
|
||||
w: w,
|
||||
Left: limit,
|
||||
w: w,
|
||||
limit: limit,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *LineWriter) Write(data []byte) (n int, err error) {
|
||||
if l.Left <= 0 {
|
||||
err = ErrOversizedMessage
|
||||
return
|
||||
}
|
||||
wr := len(data)
|
||||
dl := len(data)
|
||||
data = bytes.Replace(data, []byte{13, 10}, []byte{10}, -1)
|
||||
n, err = l.w.Write(data)
|
||||
l.Left -= int64(n)
|
||||
if err != nil {
|
||||
return n, err
|
||||
parts := bytes.Split(data, []byte{10})
|
||||
for _, part := range parts {
|
||||
for len(part) > l.limit {
|
||||
d := make([]byte, l.limit)
|
||||
copy(d, part[:l.limit])
|
||||
d = append(d, 10)
|
||||
_, err = l.w.Write(d)
|
||||
part = part[l.limit:]
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
part = append(part, 10)
|
||||
_, err = l.w.Write(part)
|
||||
}
|
||||
n = wr
|
||||
n = dl
|
||||
return
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ func (self *nntpArticle) WriteBody(wr io.Writer, limit int64) (err error) {
|
||||
|
||||
boundary, ok := params["boundary"]
|
||||
if ok {
|
||||
nlw := NewLineWriter(wr, limit)
|
||||
nlw := NewLineWriter(wr, 80)
|
||||
w := multipart.NewWriter(nlw)
|
||||
|
||||
err = w.SetBoundary(boundary)
|
||||
@ -426,7 +426,7 @@ func (self *nntpArticle) WriteBody(wr io.Writer, limit int64) (err error) {
|
||||
continue
|
||||
}
|
||||
hdr := att.Header()
|
||||
hdr.Add("Content-Transfer-Encoding", "base64")
|
||||
hdr.Set("Content-Transfer-Encoding", "base64")
|
||||
part, err := w.CreatePart(hdr)
|
||||
if err != nil {
|
||||
log.Println("failed to create part?", err)
|
||||
@ -452,7 +452,7 @@ func (self *nntpArticle) WriteBody(wr io.Writer, limit int64) (err error) {
|
||||
err = w.Close()
|
||||
w = nil
|
||||
} else {
|
||||
nlw := NewLineWriter(wr, limit)
|
||||
nlw := NewLineWriter(wr, 80)
|
||||
// write out message
|
||||
_, err = io.WriteString(nlw, self.message)
|
||||
}
|
||||
|
@ -541,7 +541,7 @@ func read_message_body(body io.Reader, hdr map[string][]string, store ArticleSto
|
||||
partReader := multipart.NewReader(body, boundary)
|
||||
for {
|
||||
part, err := partReader.NextPart()
|
||||
if err == io.EOF || err == io.ErrUnexpectedEOF {
|
||||
if part == nil {
|
||||
callback(nntp)
|
||||
return nil
|
||||
} else if err == nil {
|
||||
|
Reference in New Issue
Block a user