Archived
1
0

Merge pull request #171 from cathugger/master

use correct header, reserve some msgids, tweaks
This commit is contained in:
Jeff 2018-12-14 19:11:45 -05:00 committed by GitHub
commit e2ac75fee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -743,7 +743,7 @@ func (self *httpFrontend) handle_postRequest(pr *postRequest, b bannedFunc, e er
}
ref := pr.Reference
if len(ref) > 0 {
if ref != "" {
if ValidMessageID(ref) {
if self.daemon.database.HasArticleLocal(ref) {
nntp.headers.Set("References", ref)
@ -796,7 +796,7 @@ func (self *httpFrontend) handle_postRequest(pr *postRequest, b bannedFunc, e er
}
nntp.headers.Set("Subject", safeHeader(subject))
if isSage(subject) {
if isSage(subject) && ref != "" {
nntp.headers.Set("X-Sage", "1")
}
@ -821,7 +821,7 @@ func (self *httpFrontend) handle_postRequest(pr *postRequest, b bannedFunc, e er
msgid = genMessageID(pr.Frontend)
}
nntp.headers.Set("From", formatAddress(safeHeader(name), "poster@" + pr.Frontend))
nntp.headers.Set("From", formatAddress(safeHeader(name), "poster@"+pr.Frontend))
nntp.headers.Set("Message-ID", msgid)
// set message
@ -834,7 +834,21 @@ func (self *httpFrontend) handle_postRequest(pr *postRequest, b bannedFunc, e er
}
if len(cites) > 0 {
nntp.headers.Set("Reply-To", strings.Join(cites, " "))
if ref == "" && len(cites) == 1 {
/*
this is workaround for:
{RFC 5322}
If the parent message does not contain
a "References:" field but does have an "In-Reply-To:" field
containing a single message identifier, then the "References:" field
will contain the contents of the parent's "In-Reply-To:" field
followed by the contents of the parent's "Message-ID:" field (if
any).
*/
cites = append(cites, "<0>")
}
nntp.headers.Set("In-Reply-To", strings.Join(cites, " "))
}
// set date

View File

@ -92,6 +92,10 @@ func ValidMessageID(id string) bool {
strings.IndexAny(id[1:len(id)-1], "/\\") < 0
}
func ReservedMessageID(id string) bool {
return id == "<0>" || id == "<keepalive@dummy.tld>"
}
// message id hash
func HashMessageID(msgid string) string {
return fmt.Sprintf("%x", sha1.Sum([]byte(msgid)))
@ -898,7 +902,7 @@ func storeMessage(daemon *NNTPDaemon, hdr textproto.MIMEHeader, body io.Reader)
log.Println("dropping message with invalid mime header, no message-id")
_, err = io.Copy(Discard, body)
return
} else if ValidMessageID(msgid) {
} else if ValidMessageID(msgid) && !ReservedMessageID(msgid) {
f = daemon.store.CreateFile(msgid)
} else {
// invalid message-id
@ -914,9 +918,9 @@ func storeMessage(daemon *NNTPDaemon, hdr textproto.MIMEHeader, body io.Reader)
}
// ask for replies
replyTos := strings.Split(hdr.Get("Reply-To"), " ")
replyTos := strings.Split(hdr.Get("In-Reply-To"), " ")
for _, reply := range replyTos {
if ValidMessageID(reply) {
if ValidMessageID(reply) && !ReservedMessageID(reply) {
if !daemon.store.HasArticle(reply) {
go daemon.askForArticle(reply)
}