Best Syzkaller code snippet using main.handleEmailBounce
reporting_email.go
Source:reporting_email.go
...23// Email reporting interface.24func initEmailReporting() {25 http.HandleFunc("/email_poll", handleEmailPoll)26 http.HandleFunc("/_ah/mail/", handleIncomingMail)27 http.HandleFunc("/_ah/bounce", handleEmailBounce)28 mailingLists = make(map[string]bool)29 for _, cfg := range config.Namespaces {30 for _, reporting := range cfg.Reporting {31 if cfg, ok := reporting.Config.(*EmailConfig); ok {32 mailingLists[email.CanonicalEmail(cfg.Email)] = true33 }34 }35 }36}37const (38 emailType = "email"39 // This plays an important role at least for job replies.40 // If we CC a kernel mailing list and it uses Patchwork,41 // then any emails with a patch attached create a new patch42 // entry pending for review. The prefix makes Patchwork43 // treat it as a comment for a previous patch.44 replySubjectPrefix = "Re: "45 replyNoBugID = "I see the command but can't find the corresponding bug.\n" +46 "Please resend the email to %[1]v address\n" +47 "that is the sender of the bug report (also present in the Reported-by tag)."48 replyBadBugID = "I see the command but can't find the corresponding bug.\n" +49 "The email is sent to %[1]v address\n" +50 "but the HASH does not correspond to any known bug.\n" +51 "Please double check the address."52)53var mailingLists map[string]bool54type EmailConfig struct {55 Email string56 MailMaintainers bool57 DefaultMaintainers []string58}59func (cfg *EmailConfig) Type() string {60 return emailType61}62func (cfg *EmailConfig) Validate() error {63 if _, err := mail.ParseAddress(cfg.Email); err != nil {64 return fmt.Errorf("bad email address %q: %v", cfg.Email, err)65 }66 for _, email := range cfg.DefaultMaintainers {67 if _, err := mail.ParseAddress(email); err != nil {68 return fmt.Errorf("bad email address %q: %v", email, err)69 }70 }71 if cfg.MailMaintainers && len(cfg.DefaultMaintainers) == 0 {72 return fmt.Errorf("MailMaintainers is set but no DefaultMaintainers")73 }74 return nil75}76// handleEmailPoll is called by cron and sends emails for new bugs, if any.77func handleEmailPoll(w http.ResponseWriter, r *http.Request) {78 c := appengine.NewContext(r)79 if err := emailPollJobs(c); err != nil {80 log.Errorf(c, "job poll failed: %v", err)81 http.Error(w, err.Error(), http.StatusInternalServerError)82 return83 }84 if err := emailPollNotifications(c); err != nil {85 log.Errorf(c, "notif poll failed: %v", err)86 http.Error(w, err.Error(), http.StatusInternalServerError)87 return88 }89 if err := emailPollBugs(c); err != nil {90 log.Errorf(c, "bug poll failed: %v", err)91 http.Error(w, err.Error(), http.StatusInternalServerError)92 return93 }94 w.Write([]byte("OK"))95}96func emailPollBugs(c context.Context) error {97 reports := reportingPollBugs(c, emailType)98 for _, rep := range reports {99 if err := emailSendBugReport(c, rep); err != nil {100 log.Errorf(c, "emailPollBugs: %v", err)101 }102 }103 return nil104}105func emailSendBugReport(c context.Context, rep *dashapi.BugReport) error {106 cfg := new(EmailConfig)107 if err := json.Unmarshal(rep.Config, cfg); err != nil {108 return fmt.Errorf("failed to unmarshal email config: %v", err)109 }110 if err := emailReport(c, rep); err != nil {111 return fmt.Errorf("failed to report bug: %v", err)112 }113 cmd := &dashapi.BugUpdate{114 ID: rep.ID,115 Status: dashapi.BugStatusOpen,116 ReproLevel: dashapi.ReproLevelNone,117 CrashID: rep.CrashID,118 }119 if len(rep.ReproC) != 0 {120 cmd.ReproLevel = dashapi.ReproLevelC121 } else if len(rep.ReproSyz) != 0 {122 cmd.ReproLevel = dashapi.ReproLevelSyz123 }124 ok, reason, err := incomingCommand(c, cmd)125 if !ok || err != nil {126 return fmt.Errorf("failed to update reported bug: ok=%v reason=%v err=%v", ok, reason, err)127 }128 return nil129}130func emailPollNotifications(c context.Context) error {131 notifs := reportingPollNotifications(c, emailType)132 for _, notif := range notifs {133 if err := emailSendBugNotif(c, notif); err != nil {134 log.Errorf(c, "emailPollNotifications: %v", err)135 }136 }137 return nil138}139func emailSendBugNotif(c context.Context, notif *dashapi.BugNotification) error {140 status, body := dashapi.BugStatusOpen, ""141 switch notif.Type {142 case dashapi.BugNotifUpstream:143 body = "Sending this report upstream."144 status = dashapi.BugStatusUpstream145 case dashapi.BugNotifBadCommit:146 days := int(notifyAboutBadCommitPeriod / time.Hour / 24)147 body = fmt.Sprintf("This bug is marked as fixed by commit:\n%v\n"+148 "But I can't find it in any tested tree for more than %v days.\n"+149 "Is it a correct commit? Please update it by replying:\n"+150 "#syz fix: exact-commit-title\n"+151 "Until then the bug is still considered open and\n"+152 "new crashes with the same signature are ignored.\n",153 notif.Text, days)154 case dashapi.BugNotifObsoleted:155 body = "Auto-closing this bug as obsolete.\n" +156 "Crashes did not happen for a while, no reproducer and no activity."157 status = dashapi.BugStatusInvalid158 default:159 return fmt.Errorf("bad notification type %v", notif.Type)160 }161 cfg := new(EmailConfig)162 if err := json.Unmarshal(notif.Config, cfg); err != nil {163 return fmt.Errorf("failed to unmarshal email config: %v", err)164 }165 to := email.MergeEmailLists([]string{cfg.Email}, notif.CC)166 if cfg.MailMaintainers && notif.Public {167 to = email.MergeEmailLists(to, notif.Maintainers, cfg.DefaultMaintainers)168 }169 from, err := email.AddAddrContext(fromAddr(c), notif.ID)170 if err != nil {171 return err172 }173 log.Infof(c, "sending notif %v for %q to %q: %v", notif.Type, notif.Title, to, body)174 if err := sendMailText(c, notif.Title, from, to, notif.ExtID, nil, body); err != nil {175 return err176 }177 cmd := &dashapi.BugUpdate{178 ID: notif.ID,179 Status: status,180 Notification: true,181 }182 ok, reason, err := incomingCommand(c, cmd)183 if !ok || err != nil {184 return fmt.Errorf("notif update failed: ok=%v reason=%v err=%v", ok, reason, err)185 }186 return nil187}188func emailPollJobs(c context.Context) error {189 jobs, err := pollCompletedJobs(c, emailType)190 if err != nil {191 return err192 }193 for _, job := range jobs {194 if err := emailReport(c, job); err != nil {195 log.Errorf(c, "failed to report job: %v", err)196 continue197 }198 if err := jobReported(c, job.JobID); err != nil {199 log.Errorf(c, "failed to mark job reported: %v", err)200 continue201 }202 }203 return nil204}205func emailReport(c context.Context, rep *dashapi.BugReport) error {206 templ, public := "", false207 switch rep.Type {208 case dashapi.ReportNew, dashapi.ReportRepro:209 templ = "mail_bug.txt"210 public = true211 case dashapi.ReportTestPatch:212 templ = "mail_test_result.txt"213 case dashapi.ReportBisectCause, dashapi.ReportBisectFix:214 templ = "mail_bisect_result.txt"215 public = true216 default:217 return fmt.Errorf("unknown report type %v", rep.Type)218 }219 cfg := new(EmailConfig)220 if err := json.Unmarshal(rep.Config, cfg); err != nil {221 return fmt.Errorf("failed to unmarshal email config: %v", err)222 }223 to := email.MergeEmailLists([]string{cfg.Email}, rep.CC)224 if cfg.MailMaintainers && public {225 to = email.MergeEmailLists(to, rep.Maintainers, cfg.DefaultMaintainers)226 }227 from, err := email.AddAddrContext(fromAddr(c), rep.ID)228 if err != nil {229 return err230 }231 log.Infof(c, "sending email %q to %q", rep.Title, to)232 return sendMailTemplate(c, rep.Title, from, to, rep.ExtID, nil, templ, rep)233}234// handleIncomingMail is the entry point for incoming emails.235func handleIncomingMail(w http.ResponseWriter, r *http.Request) {236 c := appengine.NewContext(r)237 if err := incomingMail(c, r); err != nil {238 log.Errorf(c, "handleIncomingMail: %v", err)239 }240}241func incomingMail(c context.Context, r *http.Request) error {242 msg, err := email.Parse(r.Body, ownEmails(c))243 if err != nil {244 // Malformed emails constantly appear from spammers.245 // But we have not seen errors parsing legit emails.246 // These errors are annoying. Warn and ignore them.247 log.Warningf(c, "failed to parse email: %v", err)248 return nil249 }250 // Ignore any incoming emails from syzbot itself.251 if ownEmail(c) == msg.From {252 return nil253 }254 log.Infof(c, "received email: subject %q, from %q, cc %q, msg %q, bug %q, cmd %q, link %q",255 msg.Subject, msg.From, msg.Cc, msg.MessageID, msg.BugID, msg.Command, msg.Link)256 if msg.Command == email.CmdFix && msg.CommandArgs == "exact-commit-title" {257 // Sometimes it happens that somebody sends us our own text back, ignore it.258 msg.Command, msg.CommandArgs = email.CmdNone, ""259 }260 bug, _, reporting := loadBugInfo(c, msg)261 if bug == nil {262 return nil // error was already logged263 }264 emailConfig := reporting.Config.(*EmailConfig)265 // A mailing list can send us a duplicate email, to not process/reply266 // to such duplicate emails, we ignore emails coming from our mailing lists.267 mailingList := email.CanonicalEmail(emailConfig.Email)268 fromMailingList := email.CanonicalEmail(msg.From) == mailingList269 mailingListInCC := checkMailingListInCC(c, msg, mailingList)270 log.Infof(c, "from/cc mailing list: %v/%v", fromMailingList, mailingListInCC)271 if msg.Command == email.CmdTest {272 return handleTestCommand(c, msg)273 }274 if fromMailingList && msg.Command != email.CmdNone {275 log.Infof(c, "duplicate email from mailing list, ignoring")276 return nil277 }278 cmd := &dashapi.BugUpdate{279 Status: emailCmdToStatus[msg.Command],280 ID: msg.BugID,281 ExtID: msg.MessageID,282 Link: msg.Link,283 CC: msg.Cc,284 }285 switch msg.Command {286 case email.CmdNone, email.CmdUpstream, email.CmdInvalid, email.CmdUnDup:287 case email.CmdFix:288 if msg.CommandArgs == "" {289 return replyTo(c, msg, "no commit title", nil)290 }291 cmd.FixCommits = []string{msg.CommandArgs}292 case email.CmdDup:293 if msg.CommandArgs == "" {294 return replyTo(c, msg, "no dup title", nil)295 }296 cmd.DupOf = msg.CommandArgs297 case email.CmdUnCC:298 cmd.CC = []string{email.CanonicalEmail(msg.From)}299 default:300 if msg.Command != email.CmdUnknown {301 log.Errorf(c, "unknown email command %v %q", msg.Command, msg.CommandStr)302 }303 return replyTo(c, msg, fmt.Sprintf("unknown command %q", msg.CommandStr), nil)304 }305 ok, reply, err := incomingCommand(c, cmd)306 if err != nil {307 return nil // the error was already logged308 }309 if !ok && reply != "" {310 return replyTo(c, msg, reply, nil)311 }312 if !mailingListInCC && msg.Command != email.CmdNone && msg.Command != email.CmdUnCC {313 warnMailingListInCC(c, msg, mailingList)314 }315 return nil316}317var emailCmdToStatus = map[email.Command]dashapi.BugStatus{318 email.CmdNone: dashapi.BugStatusUpdate,319 email.CmdUpstream: dashapi.BugStatusUpstream,320 email.CmdInvalid: dashapi.BugStatusInvalid,321 email.CmdUnDup: dashapi.BugStatusOpen,322 email.CmdFix: dashapi.BugStatusOpen,323 email.CmdDup: dashapi.BugStatusDup,324 email.CmdUnCC: dashapi.BugStatusUnCC,325}326func handleTestCommand(c context.Context, msg *email.Email) error {327 args := strings.Split(msg.CommandArgs, " ")328 if len(args) != 2 {329 return replyTo(c, msg, fmt.Sprintf("want 2 args (repo, branch), got %v", len(args)), nil)330 }331 reply := handleTestRequest(c, msg.BugID, email.CanonicalEmail(msg.From),332 msg.MessageID, msg.Link, msg.Patch, args[0], args[1], msg.Cc)333 if reply != "" {334 return replyTo(c, msg, reply, nil)335 }336 return nil337}338func handleEmailBounce(w http.ResponseWriter, r *http.Request) {339 c := appengine.NewContext(r)340 body, err := ioutil.ReadAll(r.Body)341 if err != nil {342 log.Errorf(c, "email bounced: failed to read body: %v", err)343 return344 }345 if nonCriticalBounceRe.Match(body) {346 log.Infof(c, "email bounced: address not found")347 } else {348 log.Errorf(c, "email bounced")349 }350 log.Infof(c, "%s", body)351}352// These are just stale emails in MAINTAINERS....
bounce.go
Source:bounce.go
1package main2import (3 "encoding/json"4 "fmt"5 "mojo/db"6 "mojo/util"7 "net/http"8 "time"9)10// This module handles the bounce messages from AWS SNS.11//12// For reference:13// bounce object: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#bounce-object14// complaint object: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#complaint-object15// delivery object: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#delivery-object16// AwsMailNotification is the data type associated with the AWS mail notification17type AwsMailNotification struct {18 Timestamp time.Time `json:"timestamp"`19 Source string `json:"source"`20 SourceArn string `json:"sourceArn"`21 SourceIP string `json:"sourceIp"`22 SendingAccountID string `json:"sendingAccountId"`23 MessageID string `json:"messageId"`24 Destination []string `json:"destination"`25 HeadersTruncated bool `json:"headersTruncated"`26 Headers []struct {27 Name string `json:"name"`28 Value string `json:"value"`29 } `json:"headers"`30 CommonHeaders struct {31 From []string `json:"from"`32 Date string `json:"date"`33 To []string `json:"to"`34 MessageID string `json:"messageId"`35 Subject string `json:"subject"`36 } `json:"commonHeaders"`37}38// AwsBounceNotification is the data type for an AWS Bounced email message notification39type AwsBounceNotification struct {40 NotificationType string `json:"notificationType"`41 Bounce struct {42 BounceType string `json:"bounceType"`43 BounceSubType string `json:"bounceSubType"`44 BouncedRecipients []struct {45 EmailAddress string `json:"emailAddress"`46 Action string `json:"action"`47 Status string `json:"status"`48 DiagnosticCode string `json:"diagnosticCode"`49 } `json:"bouncedRecipients"`50 Timestamp time.Time `json:"timestamp"`51 FeedbackID string `json:"feedbackId"`52 RemoteMtaIP string `json:"remoteMtaIp"`53 ReportingMTA string `json:"reportingMTA"`54 } `json:"bounce"`55}56// ChangePersonStatus is called with the email address of the person57// to be updated. If found, the person's status will be set to the58// supplied value.59func ChangePersonStatus(s string, status int64) error {60 util.Console("Entered ChangePersonStatus: looking for %s\n", s)61 p, err := db.GetPersonByEmail(s)62 if err != nil {63 util.Console("Error with GetPersonByEmail(%s): %s\n", s, err.Error())64 util.Ulog("ChangePersonStatus: error getting Person with Email = %s\n", s)65 return err66 }67 util.Console("Found %s, updating status to %d\n", p.Email1, status)68 p.Status = status69 p.OptOutDate = time.Now()70 return db.UpdatePerson(&p)71}72// HandleEmailBounce is called with the bounced email address. It will73// update the associated person record with a status of BOUNCED74func HandleEmailBounce(s string) error {75 return ChangePersonStatus(s, db.BOUNCED)76}77// HandleEmailSuppression is called with the bounced email address due to78// amazon's suppression list. It will update the associated person record79// with a status of SUPPRESSED80func HandleEmailSuppression(s string) error {81 return ChangePersonStatus(s, db.SUPPRESSED)82}83// HandleEmailComplaint is called with the bounced email address. It will84// update the associated person record with a status of COMPLAINT85func HandleEmailComplaint(s string) error {86 return ChangePersonStatus(s, db.COMPLAINT)87}88// SvcHandlerAwsBouncedEmail removes a bounced email address from the database89func SvcHandlerAwsBouncedEmail(w http.ResponseWriter, r *http.Request, d *ServiceData, a *AwsNotificationEnvelope) {90 funcname := "SvcHandlerAwsBouncedEmail"91 util.Console("Entered %s\n", funcname)92 var b AwsBounceNotification93 err := json.Unmarshal([]byte(a.Message), &b)94 if err != nil {95 e := fmt.Errorf("%s: Error with json.Unmarshal: %s", funcname, err.Error())96 util.LogAndPrintError(funcname, e)97 return98 }99 util.Console("\nTHIRD UNMARSHAL SUCCESS!\n")100 util.Console("Received Bounced Email Message!\n")101 // fmt.Printf("%#v\n", b)102 for i := 0; i < len(b.Bounce.BouncedRecipients); i++ {103 fmt.Printf("Email address to remove: %s\n", b.Bounce.BouncedRecipients[i].EmailAddress)104 switch b.Bounce.BounceSubType {105 case "Suppressed":106 err = HandleEmailSuppression(b.Bounce.BouncedRecipients[i].EmailAddress)107 default:108 err = HandleEmailBounce(b.Bounce.BouncedRecipients[i].EmailAddress)109 }110 if err != nil {111 util.Ulog("%s: Error handling bounce: %s\n", funcname, err.Error())112 }113 }114}...
handleEmailBounce
Using AI Code Generation
1import (2func main() {3 http.HandleFunc("/email-bounce", handleEmailBounce)4 log.Fatal(http.ListenAndServe(":8080", nil))5}6func handleEmailBounce(w http.ResponseWriter, r *http.Request) {7 r.ParseForm()8 fmt.Println("Email Bounce: " + r.FormValue("email"))9}10import (11func main() {
handleEmailBounce
Using AI Code Generation
1func main() {2}3func main() {4}5func main() {6}7func main() {8}9func main() {10}11func main() {12}13func main() {14}15func main() {16}17func main() {18}19func main() {20}21func main() {22}23func main() {24}25func main() {26}
handleEmailBounce
Using AI Code Generation
1import (2func main() {3 http.HandleFunc("/email/bounce", handleEmailBounce)4 http.ListenAndServe(":8080", nil)5}6func handleEmailBounce(w http.ResponseWriter, r *http.Request) {7 queryParams := r.URL.Query()8 email := queryParams.Get("email")9 bounceType := queryParams.Get("bounce_type")10 bounceReason := queryParams.Get("bounce_reason")11 bounceTime := queryParams.Get("bounce_time")12 conn, err := getRedisConnection()13 if err != nil {14 log.Fatalf("Error in getting redis connection: %v", err)15 }16 defer conn.Close()17 redisKey := getRedisKey(email)18 redisValue := getRedisValue(bounceType, bounceReason, bounceTime)19 _, err = conn.Do("SET", redisKey, redisValue)20 if err != nil {21 log.Fatalf("Error in setting redis key value: %v", err)22 }23}24func getRedisConnection() (redis.Conn, error) {25 redisAddress := os.Getenv("REDIS_ADDRESS")26 redisPassword := os.Getenv("REDIS_PASSWORD")27 redisDb, err := strconv.Atoi(os.Getenv("REDIS_DB"))28 if err != nil {29 log.Fatalf("Error in converting redis db to integer: %v", err)30 }31 conn, err := redis.Dial("tcp", redisAddress)32 if err != nil {33 }34 _, err = conn.Do("AUTH", redisPassword)35 if err != nil {36 }37 _, err = conn.Do("SELECT", redisDb)38 if err != nil {39 }40}
handleEmailBounce
Using AI Code Generation
1main.handleEmailBounce()2main.handleEmailBounce()3main.handleEmailBounce()4main.handleEmailBounce()5main.handleEmailBounce()6main.handleEmailBounce()7main.handleEmailBounce()8main.handleEmailBounce()9main.handleEmailBounce()10main.handleEmailBounce()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!