Best Syzkaller code snippet using main.sendMailText
reporting_email.go
Source:reporting_email.go
...174 if err != nil {175 return err176 }177 log.Infof(c, "sending notif %v for %q to %q: %v", notif.Type, notif.Title, to, body)178 if err := sendMailText(c, cfg, notif.Title, from, to, notif.ExtID, body); err != nil {179 return err180 }181 cmd := &dashapi.BugUpdate{182 ID: notif.ID,183 Status: status,184 Notification: true,185 }186 ok, reason, err := incomingCommand(c, cmd)187 if !ok || err != nil {188 return fmt.Errorf("notif update failed: ok=%v reason=%v err=%v", ok, reason, err)189 }190 return nil191}192func emailPollJobs(c context.Context) error {193 jobs, err := pollCompletedJobs(c, emailType)194 if err != nil {195 return err196 }197 for _, job := range jobs {198 if err := emailReport(c, job); err != nil {199 log.Errorf(c, "failed to report job: %v", err)200 continue201 }202 if err := jobReported(c, job.JobID); err != nil {203 log.Errorf(c, "failed to mark job reported: %v", err)204 continue205 }206 }207 return nil208}209func emailReport(c context.Context, rep *dashapi.BugReport) error {210 templ, public := "", false211 switch rep.Type {212 case dashapi.ReportNew, dashapi.ReportRepro:213 templ = "mail_bug.txt"214 public = true215 case dashapi.ReportTestPatch:216 templ = "mail_test_result.txt"217 case dashapi.ReportBisectCause, dashapi.ReportBisectFix:218 templ = "mail_bisect_result.txt"219 public = true220 default:221 return fmt.Errorf("unknown report type %v", rep.Type)222 }223 cfg := new(EmailConfig)224 if err := json.Unmarshal(rep.Config, cfg); err != nil {225 return fmt.Errorf("failed to unmarshal email config: %v", err)226 }227 to := email.MergeEmailLists([]string{cfg.Email}, rep.CC)228 if cfg.MailMaintainers && public {229 to = email.MergeEmailLists(to, rep.Maintainers, cfg.DefaultMaintainers)230 }231 from, err := email.AddAddrContext(fromAddr(c), rep.ID)232 if err != nil {233 return err234 }235 body := new(bytes.Buffer)236 if err := mailTemplates.ExecuteTemplate(body, templ, rep); err != nil {237 return fmt.Errorf("failed to execute %v template: %v", templ, err)238 }239 log.Infof(c, "sending email %q to %q", rep.Title, to)240 return sendMailText(c, cfg, rep.Title, from, to, rep.ExtID, body.String())241}242// handleIncomingMail is the entry point for incoming emails.243func handleIncomingMail(w http.ResponseWriter, r *http.Request) {244 c := appengine.NewContext(r)245 if err := incomingMail(c, r); err != nil {246 log.Errorf(c, "handleIncomingMail: %v", err)247 }248}249func incomingMail(c context.Context, r *http.Request) error {250 msg, err := email.Parse(r.Body, ownEmails(c))251 if err != nil {252 // Malformed emails constantly appear from spammers.253 // But we have not seen errors parsing legit emails.254 // These errors are annoying. Warn and ignore them.255 log.Warningf(c, "failed to parse email: %v", err)256 return nil257 }258 // Ignore any incoming emails from syzbot itself.259 if ownEmail(c) == msg.From {260 return nil261 }262 log.Infof(c, "received email: subject %q, from %q, cc %q, msg %q, bug %q, cmd %q, link %q",263 msg.Subject, msg.From, msg.Cc, msg.MessageID, msg.BugID, msg.Command, msg.Link)264 if msg.Command == email.CmdFix && msg.CommandArgs == "exact-commit-title" {265 // Sometimes it happens that somebody sends us our own text back, ignore it.266 msg.Command, msg.CommandArgs = email.CmdNone, ""267 }268 bug, _, reporting := loadBugInfo(c, msg)269 if bug == nil {270 return nil // error was already logged271 }272 emailConfig := reporting.Config.(*EmailConfig)273 // A mailing list can send us a duplicate email, to not process/reply274 // to such duplicate emails, we ignore emails coming from our mailing lists.275 mailingList := email.CanonicalEmail(emailConfig.Email)276 fromMailingList := email.CanonicalEmail(msg.From) == mailingList277 mailingListInCC := checkMailingListInCC(c, msg, mailingList)278 log.Infof(c, "from/cc mailing list: %v/%v", fromMailingList, mailingListInCC)279 if msg.Command == email.CmdTest {280 return handleTestCommand(c, msg)281 }282 if fromMailingList && msg.Command != email.CmdNone {283 log.Infof(c, "duplicate email from mailing list, ignoring")284 return nil285 }286 cmd := &dashapi.BugUpdate{287 Status: emailCmdToStatus[msg.Command],288 ID: msg.BugID,289 ExtID: msg.MessageID,290 Link: msg.Link,291 CC: msg.Cc,292 }293 switch msg.Command {294 case email.CmdNone, email.CmdUpstream, email.CmdInvalid, email.CmdUnDup:295 case email.CmdFix:296 if msg.CommandArgs == "" {297 return replyTo(c, msg, "no commit title")298 }299 cmd.FixCommits = []string{msg.CommandArgs}300 case email.CmdUnFix:301 cmd.ResetFixCommits = true302 case email.CmdDup:303 if msg.CommandArgs == "" {304 return replyTo(c, msg, "no dup title")305 }306 cmd.DupOf = msg.CommandArgs307 cmd.DupOf = strings.TrimSpace(strings.TrimPrefix(cmd.DupOf, replySubjectPrefix))308 cmd.DupOf = strings.TrimSpace(strings.TrimPrefix(cmd.DupOf, emailConfig.SubjectPrefix))309 case email.CmdUnCC:310 cmd.CC = []string{email.CanonicalEmail(msg.From)}311 default:312 if msg.Command != email.CmdUnknown {313 log.Errorf(c, "unknown email command %v %q", msg.Command, msg.CommandStr)314 }315 return replyTo(c, msg, fmt.Sprintf("unknown command %q", msg.CommandStr))316 }317 ok, reply, err := incomingCommand(c, cmd)318 if err != nil {319 return nil // the error was already logged320 }321 if !ok && reply != "" {322 return replyTo(c, msg, reply)323 }324 if !mailingListInCC && msg.Command != email.CmdNone && msg.Command != email.CmdUnCC {325 warnMailingListInCC(c, msg, mailingList)326 }327 return nil328}329var emailCmdToStatus = map[email.Command]dashapi.BugStatus{330 email.CmdNone: dashapi.BugStatusUpdate,331 email.CmdUpstream: dashapi.BugStatusUpstream,332 email.CmdInvalid: dashapi.BugStatusInvalid,333 email.CmdUnDup: dashapi.BugStatusOpen,334 email.CmdFix: dashapi.BugStatusOpen,335 email.CmdUnFix: dashapi.BugStatusUpdate,336 email.CmdDup: dashapi.BugStatusDup,337 email.CmdUnCC: dashapi.BugStatusUnCC,338}339func handleTestCommand(c context.Context, msg *email.Email) error {340 args := strings.Split(msg.CommandArgs, " ")341 if len(args) != 2 {342 return replyTo(c, msg, fmt.Sprintf("want 2 args (repo, branch), got %v", len(args)))343 }344 reply := handleTestRequest(c, msg.BugID, email.CanonicalEmail(msg.From),345 msg.MessageID, msg.Link, msg.Patch, args[0], args[1], msg.Cc)346 if reply != "" {347 return replyTo(c, msg, reply)348 }349 return nil350}351func handleEmailBounce(w http.ResponseWriter, r *http.Request) {352 c := appengine.NewContext(r)353 body, err := ioutil.ReadAll(r.Body)354 if err != nil {355 log.Errorf(c, "email bounced: failed to read body: %v", err)356 return357 }358 if nonCriticalBounceRe.Match(body) {359 log.Infof(c, "email bounced: address not found")360 } else {361 log.Errorf(c, "email bounced")362 }363 log.Infof(c, "%s", body)364}365// These are just stale emails in MAINTAINERS.366var nonCriticalBounceRe = regexp.MustCompile(`\*\* Address not found \*\*|550 #5\.1\.0 Address rejected`)367func loadBugInfo(c context.Context, msg *email.Email) (bug *Bug, bugReporting *BugReporting, reporting *Reporting) {368 if msg.BugID == "" {369 if msg.Command == email.CmdNone {370 // This happens when people CC syzbot on unrelated emails.371 log.Infof(c, "no bug ID (%q)", msg.Subject)372 } else {373 log.Errorf(c, "no bug ID (%q)", msg.Subject)374 from, err := email.AddAddrContext(ownEmail(c), "HASH")375 if err != nil {376 log.Errorf(c, "failed to format sender email address: %v", err)377 from = "ERROR"378 }379 if err := replyTo(c, msg, fmt.Sprintf(replyNoBugID, from)); err != nil {380 log.Errorf(c, "failed to send reply: %v", err)381 }382 }383 return nil, nil, nil384 }385 bug, _, err := findBugByReportingID(c, msg.BugID)386 if err != nil {387 log.Errorf(c, "can't find bug: %v", err)388 from, err := email.AddAddrContext(ownEmail(c), "HASH")389 if err != nil {390 log.Errorf(c, "failed to format sender email address: %v", err)391 from = "ERROR"392 }393 if err := replyTo(c, msg, fmt.Sprintf(replyBadBugID, from)); err != nil {394 log.Errorf(c, "failed to send reply: %v", err)395 }396 return nil, nil, nil397 }398 bugReporting, _ = bugReportingByID(bug, msg.BugID)399 if bugReporting == nil {400 log.Errorf(c, "can't find bug reporting: %v", err)401 if err := replyTo(c, msg, "Can't find the corresponding bug."); err != nil {402 log.Errorf(c, "failed to send reply: %v", err)403 }404 return nil, nil, nil405 }406 reporting = config.Namespaces[bug.Namespace].ReportingByName(bugReporting.Name)407 if reporting == nil {408 log.Errorf(c, "can't find reporting for this bug: namespace=%q reporting=%q",409 bug.Namespace, bugReporting.Name)410 return nil, nil, nil411 }412 if reporting.Config.Type() != emailType {413 log.Errorf(c, "reporting is not email: namespace=%q reporting=%q config=%q",414 bug.Namespace, bugReporting.Name, reporting.Config.Type())415 return nil, nil, nil416 }417 return bug, bugReporting, reporting418}419func checkMailingListInCC(c context.Context, msg *email.Email, mailingList string) bool {420 if email.CanonicalEmail(msg.From) == mailingList {421 return true422 }423 for _, cc := range msg.Cc {424 if email.CanonicalEmail(cc) == mailingList {425 return true426 }427 }428 msg.Cc = append(msg.Cc, mailingList)429 return false430}431func warnMailingListInCC(c context.Context, msg *email.Email, mailingList string) {432 reply := fmt.Sprintf("Your '%v' command is accepted, but please keep %v mailing list"+433 " in CC next time. It serves as a history of what happened with each bug report."+434 " Thank you.",435 msg.CommandStr, mailingList)436 if err := replyTo(c, msg, reply); err != nil {437 log.Errorf(c, "failed to send email reply: %v", err)438 }439}440func sendMailText(c context.Context, cfg *EmailConfig, subject, from string, to []string, replyTo, body string) error {441 msg := &aemail.Message{442 Sender: from,443 To: to,444 Subject: subject,445 Body: body,446 }447 if cfg.SubjectPrefix != "" {448 msg.Subject = cfg.SubjectPrefix + " " + msg.Subject449 }450 if replyTo != "" {451 msg.Headers = mail.Header{"In-Reply-To": []string{replyTo}}452 msg.Subject = replySubject(msg.Subject)453 }454 return sendEmail(c, msg)...
sendMailText
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 sendMailText()5}6func sendMailText() {
sendMailText
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 sendMailText()5}6import (7func sendMailText() {8 fmt.Println("Hello, playground")
sendMailText
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 err := sendMailText("test", "test", "test", "test")5 if err != nil {6 log.Fatal("Error in sending mail: ", err)7 }8}9import (10func sendMailText(from, to, subject, body string) error {11 err := smtp.SendMail("smtp.gmail.com:587",12 smtp.PlainAuth("", "
sendMailText
Using AI Code Generation
1import (2func main() {3 err := sendMailText("Hello", "Hello, this is a test email")4 if err != nil {5 log.Fatal(err)6 }7 fmt.Println("Email sent successfully")8}9import (10func sendMailText(subject string, body string) error {
sendMailText
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello, playground")4 sendMailText()5}6import (7func sendMailText() {
sendMailText
Using AI Code Generation
1import (2func main() {3 main.sendMailText("test", "test", "test", "test")4}5func SendMailText() {6}
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!!