Archived
1
0

gay bullshit

This commit is contained in:
Jeff Becker 2017-11-06 19:09:45 -05:00
parent 99a3403ed8
commit 666549e1e4
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 25 additions and 19 deletions

View File

@ -6,29 +6,35 @@ import (
) )
type LineWriter struct { type LineWriter struct {
w io.Writer w io.Writer
Left int64 limit int
} }
func NewLineWriter(w io.Writer, limit int64) *LineWriter { func NewLineWriter(w io.Writer, limit int) *LineWriter {
return &LineWriter{ return &LineWriter{
w: w, w: w,
Left: limit, limit: limit,
} }
} }
func (l *LineWriter) Write(data []byte) (n int, err error) { func (l *LineWriter) Write(data []byte) (n int, err error) {
if l.Left <= 0 { dl := len(data)
err = ErrOversizedMessage
return
}
wr := len(data)
data = bytes.Replace(data, []byte{13, 10}, []byte{10}, -1) data = bytes.Replace(data, []byte{13, 10}, []byte{10}, -1)
n, err = l.w.Write(data) parts := bytes.Split(data, []byte{10})
l.Left -= int64(n) for _, part := range parts {
if err != nil { for len(part) > l.limit {
return n, err 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 return
} }

View File

@ -414,7 +414,7 @@ func (self *nntpArticle) WriteBody(wr io.Writer, limit int64) (err error) {
boundary, ok := params["boundary"] boundary, ok := params["boundary"]
if ok { if ok {
nlw := NewLineWriter(wr, limit) nlw := NewLineWriter(wr, 80)
w := multipart.NewWriter(nlw) w := multipart.NewWriter(nlw)
err = w.SetBoundary(boundary) err = w.SetBoundary(boundary)
@ -426,7 +426,7 @@ func (self *nntpArticle) WriteBody(wr io.Writer, limit int64) (err error) {
continue continue
} }
hdr := att.Header() hdr := att.Header()
hdr.Add("Content-Transfer-Encoding", "base64") hdr.Set("Content-Transfer-Encoding", "base64")
part, err := w.CreatePart(hdr) part, err := w.CreatePart(hdr)
if err != nil { if err != nil {
log.Println("failed to create part?", err) 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() err = w.Close()
w = nil w = nil
} else { } else {
nlw := NewLineWriter(wr, limit) nlw := NewLineWriter(wr, 80)
// write out message // write out message
_, err = io.WriteString(nlw, self.message) _, err = io.WriteString(nlw, self.message)
} }

View File

@ -541,7 +541,7 @@ func read_message_body(body io.Reader, hdr map[string][]string, store ArticleSto
partReader := multipart.NewReader(body, boundary) partReader := multipart.NewReader(body, boundary)
for { for {
part, err := partReader.NextPart() part, err := partReader.NextPart()
if err == io.EOF || err == io.ErrUnexpectedEOF { if part == nil {
callback(nntp) callback(nntp)
return nil return nil
} else if err == nil { } else if err == nil {