func (mc *MailCon) waitFor(cmd *imap.Command, origErr error) (*imap.Command, error) { var ( // rsp *imap.Response wferr error ) // 1) Check if we're missing a command and if so, return with an error if cmd == nil { // Todo: origErr could be nil here as well wferr = errors.New(fmt.Sprintf("WaitFor: Missing command, because: %s", origErr.Error())) mc.logMC(wferr.Error(), imap.LogAll) return nil, wferr } else if origErr == nil { // The original command executed without an error -> start waiting for the result of the // given command (which is done by waiting for the OK response) if _, okErr := cmd.Result(imap.OK); okErr != nil { // 2) If the result is not OK, build an WaitFor error that contains the imap.OK error wferr = errors.New(fmt.Sprintf("WaitFor: Command %s finished, but failed to wait \n"+ "for the result with error: %s", cmd.Name(true), okErr.Error())) mc.logMC(wferr.Error(), imap.LogAll) return cmd, wferr } } else if origErr != nil { // There is an error for the original executed command return cmd, origErr } // All good, no errors return cmd, nil }
func ReportOK(cmd *imap.Command, err error) *imap.Command { var rsp *imap.Response if cmd == nil { fmt.Printf("--- ??? ---\n%v\n\n", err) panic(err) } else if err == nil { rsp, err = cmd.Result(imap.OK) } if err != nil { fmt.Printf("--- %s ---\n%v\n\n", cmd.Name(true), err) panic(err) } c := cmd.Client() fmt.Printf("--- %s ---\n"+ "%d command response(s), %d unilateral response(s)\n"+ "%s %s\n\n", cmd.Name(true), len(cmd.Data), len(c.Data), rsp.Status, rsp.Info) c.Data = nil return cmd }