func main() { flag.Parse() var verbose bool if *verboseOpt == true { verbose = true } if *filename == "" { log.Fatal("--file is required") } msg := loadmsg.Message{Filename: *filename} err := msg.Load() if err != nil { log.Fatal(err) } atIdx := strings.Index(msg.ReturnPath.Address, "@") if atIdx < 0 { log.Fatalf("Unsupported Return-Path header [%s]\n", msg.ReturnPath.Address) } oobDomain := msg.ReturnPath.Address[atIdx+1:] if verbose == true { log.Printf("Got domain [%s] from Return-Path\n", oobDomain) } fileBytes, err := ioutil.ReadFile(*filename) if err != nil { log.Fatal(err) } // from/to are opposite here, since we're simulating a reply to := msg.ReturnPath.Address from, err := mail.ParseAddress(msg.Message.Header.Get("From")) if err != nil { log.Fatal(err) } oob := BuildOob(to, from.Address, string(fileBytes)) mxs, err := net.LookupMX(oobDomain) if err != nil { log.Fatal(err) } if mxs == nil || len(mxs) <= 0 { log.Fatal("No MXs for [%s]\n", oobDomain) } if verbose == true { log.Printf("Got MX [%s] for [%s]\n", mxs[0].Host, oobDomain) } smtpHost := fmt.Sprintf("%s:smtp", mxs[0].Host) if *send == true { log.Printf("Sending OOB from [%s] to [%s] via [%s]...\n", from, to, smtpHost) err = smtp.SendMail(smtpHost, nil, from.Address, []string{to}, []byte(oob)) if err != nil { log.Fatal(err) } log.Printf("Sent.\n") } else { if verbose == true { log.Printf("Would send OOB from [%s] to [%s] via [%s]\n", from.Address, to, smtpHost) } } }
func main() { flag.Parse() var verbose bool if *verboseOpt == true { verbose = true } if *filename == "" { log.Fatal("--file is required") } msg := loadmsg.Message{Filename: *filename} err := msg.Load() if err != nil { log.Fatal(err) } if *fblAddress != "" { msg.SetReturnPath(*fblAddress) } atIdx := strings.Index(msg.ReturnPath.Address, "@") if atIdx < 0 { log.Fatalf("Unsupported Return-Path header [%s]\n", msg.ReturnPath.Address) } fblDomain := msg.ReturnPath.Address[atIdx+1:] fblTo := fmt.Sprintf("fbl@%s", fblDomain) if verbose == true { if *fblAddress != "" { log.Printf("Got domain [%s] from --fblto\n", fblDomain) } else { log.Printf("Got domain [%s] from Return-Path\n", fblDomain) } } // from/to are opposite here, since we're simulating a reply fblFrom := string(msg.Recipient) arf := BuildArf(fblFrom, fblTo, msg.MSFBL, msg.CustID) if *dumpArf == true { fmt.Fprintf(os.Stdout, "%s", arf) } mxs, err := net.LookupMX(fblDomain) if err != nil { log.Fatal(err) } if mxs == nil || len(mxs) <= 0 { log.Fatal("No MXs for [%s]\n", fblDomain) } if verbose == true { log.Printf("Got MX [%s] for [%s]\n", mxs[0].Host, fblDomain) } smtpHost := fmt.Sprintf("%s:smtp", mxs[0].Host) if *send == true { log.Printf("Sending FBL from [%s] to [%s] via [%s]...\n", fblFrom, fblTo, smtpHost) err = smtp.SendMail(smtpHost, nil, fblFrom, []string{fblTo}, []byte(arf)) if err != nil { log.Fatal(err) } log.Printf("Sent.\n") } else { if verbose == true { log.Printf("Would send FBL from [%s] to [%s] via [%s]\n", fblFrom, fblTo, smtpHost) } } }