// Adds the xover file during the POST phase func SaveXOVERLineForPost(header []string, groupname string, message_id string, msgnum_str string) { var xover_line []string xover_line = append(xover_line, GenerateXOVERLineFromHeader(header, groupname, message_id, msgnum_str)) xover_file := filepath.Join(tools.MessagesFolder, "x-"+groupname+"-"+msgnum_str+"-"+message_id) err := tools.WriteMessages(xover_line, xover_file) if err != nil { log.Printf("[WTF] cannot write xover on %s", xover_file) } else { log.Printf("[FYI] xover saved in %s", xover_file) } }
func NNTP_POST_ReadAndSave(conn net.Conn, groupname string) { const layout = "0601021504" orario := time.Now() rawMsgId := tools.RandSeq(38) id_message := rawMsgId + "@" + orario.Format(layout) answer_ok := "340 Ok, recommended ID <" + id_message + ">\r\n" conn.Write([]byte(answer_ok)) log.Printf("[FYI] %s", answer_ok) var body []string var headers []string var is_header = true var body_lines int = 0 var body_bytes int = 0 scanner_h := bufio.NewScanner(conn) for { ok := scanner_h.Scan() if !ok { break } line := scanner_h.Text() if (strings.HasPrefix(line, "Newsgroups:")) && (groupname == "garbage") { log.Printf("[FYI] ng was %s", groupname) grp_hdr := strings.Split(line, ":") if grp_hdr != nil { groupname = grp_hdr[1] } log.Printf("[FYI] ng now is %s", groupname) grp_hdr = strings.Split(groupname, ",") if grp_hdr != nil { groupname = grp_hdr[0] } groupname = strings.Trim(groupname, " ") log.Printf("[FYI] tried to fix with %s", groupname) } if strings.HasPrefix(line, "Newsgroups:") { line = "Newsgroups: " + groupname log.Printf("[FYI] Normalization of NG Header as: %s", line) } if strings.HasPrefix(line, "Message-ID:") { log.Printf("[WARN] not permitted to set MSGID ->%s<-", line) continue } if strings.HasPrefix(line, "Xref:") { log.Printf("[WARN] not permitted to set Xref: ->%s<-", line) continue } if strings.HasPrefix(line, "Path:") { log.Printf("[WARN] not permitted to set Path ->%s<-", line) continue } if (line == "") && (is_header == true) { log.Printf("[FYI] body starts after empty line ->%s<-", line) is_header = false continue } if is_header { log.Printf("[FYI] header line is: ->%s<-", line) headers = append(headers, line) } else { log.Printf("[FYI] body line is: ->%s<-", line) body_lines++ body_bytes += len(line) body = append(body, line) } if line == "." { break } } headers = append(headers, "Message-ID: <"+id_message+">") headers = append(headers, "Lines: "+strconv.Itoa(body_lines)) headers = append(headers, "Bytes: "+strconv.Itoa(body_bytes)) num_message, _ := strconv.Atoi(GetLastNumByGroup(groupname)) num_message++ msgnum_str := fmt.Sprintf("%05d", num_message) headers = append(headers, "Xref: averno "+groupname+":"+msgnum_str) headers = append(headers, "Path: averno") headers = HeaderCompliance(headers) // SaveXOVERLineForPost(headers, groupname, id_message, msgnum_str) var xover []string xover = append(xover, GenerateXOVERLineFromHeader(headers, groupname, id_message, msgnum_str)) header_file := filepath.Join(tools.MessagesFolder, "h-"+groupname+"-"+msgnum_str+"-"+id_message) body_file := filepath.Join(tools.MessagesFolder, "b-"+groupname+"-"+msgnum_str+"-"+id_message) xover_file := filepath.Join(tools.MessagesFolder, "x-"+groupname+"-"+msgnum_str+"-"+id_message) err := tools.WriteMessages(headers, header_file) if err != nil { log.Printf("[WTF] cannot write headers on %s", header_file) } else { tribe.BCastMsgHeaders(headers, groupname, rawMsgId) log.Printf("[FYI] headers saved in %s", header_file) } err = tools.WriteMessages(body, body_file) if err != nil { log.Printf("[WTF] cannot write body on %s", body_file) } else { tribe.BCastMsgBody(body, groupname, rawMsgId) log.Printf("[FYI] body saved in %s", body_file) } err = tools.WriteMessages(xover, xover_file) if err != nil { log.Printf("[WTF] cannot write body on %s", body_file) } else { tribe.BCastMsgXover(xover, groupname, rawMsgId) log.Printf("[FYI] Xover saved in %s", body_file) } conn.Write([]byte("240 article posted ok\r\n")) }