Archived
1
0

use correct header, reserve some msgids, tweaks

This commit is contained in:
cathugger 2018-12-15 02:05:00 +02:00
parent 34be78da8a
commit b54e1d84da
No known key found for this signature in database
GPG Key ID: 9BADDA2DAF6F01A8
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 ref := pr.Reference
if len(ref) > 0 { if ref != "" {
if ValidMessageID(ref) { if ValidMessageID(ref) {
if self.daemon.database.HasArticleLocal(ref) { if self.daemon.database.HasArticleLocal(ref) {
nntp.headers.Set("References", 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)) nntp.headers.Set("Subject", safeHeader(subject))
if isSage(subject) { if isSage(subject) && ref != "" {
nntp.headers.Set("X-Sage", "1") 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) 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) nntp.headers.Set("Message-ID", msgid)
// set message // set message
@ -834,7 +834,21 @@ func (self *httpFrontend) handle_postRequest(pr *postRequest, b bannedFunc, e er
} }
if len(cites) > 0 { 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 // set date

View File

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