// emailOnTimeout runs fn in a goroutine. If fn is not done after d,
// a message about fnName is logged, and an e-mail about it is sent.
559389
func emailOnTimeout(fnName string, d time.Duration, fn func() error) error {
	c := make(chan error, 1)
	go func() {
		c <- fn()
	}()
	select {
	case <-time.After(d):
		log.Printf("timeout for %s, sending e-mail about it", fnName)
		m := mailGun.NewMessage(
			"noreply@perkeep.org",
			"timeout for docker on pk-web",
			"Because "+fnName+" is stuck.",
			"mathieu.lonjaret@gmail.com",
		)
		if _, _, err := mailGun.Send(m); err != nil {
			return fmt.Errorf("failed to send docker restart e-mail: %v", err)
		}
		return nil
	case err := <-c:
		return err
	}
}
743201
func (m *EmailValidatorImpl) ValidateEmail(ctx context.Context, email string, mailBoxVerify bool) (EmailVerification, error) {
	r := newHTTPRequest(m.getAddressURL("validate"))
	r.setClient(m.Client())
	r.addParameter("address", email)
	if mailBoxVerify {
		r.addParameter("mailbox_verification", "true")
	}
	r.setBasicAuth(basicAuthUser, m.APIKey())

	var response EmailVerification
	err := getResponseFromJSON(ctx, r, &response)
	if err != nil {
		return EmailVerification{}, err
	}

	return response, nil
}
915308
func NewTimeoutError(message string, retryAfterSeconds int) error {
	return &StatusError{unversioned.Status{
		Status:  unversioned.StatusFailure,
		Code:    StatusServerTimeout,
		Reason:  unversioned.StatusReasonTimeout,
		Message: fmt.Sprintf("Timeout: %s", message),
		Details: &unversioned.StatusDetails{
			RetryAfterSeconds: int32(retryAfterSeconds),
		},
	}}
}
417574
func NewTimer(fn Func, interval time.Duration, counter int) *Timer {
	id := atomic.AddInt64(&Manager.incrementID, 1)
	t := &Timer{
		ID:       id,
		fn:       fn,
		createAt: time.Now().UnixNano(),
		interval: interval,
		elapse:   int64(interval), // first execution will be after interval
		counter:  counter,
	}

	// add to manager
	Manager.ChCreatedTimer <- t
	return t
}
17123
func (c *crontime) DurationUntilNextEvent() time.Duration {
	return c.nextEvent().Sub(time.Now())
}
620601
func EmailValidator(param string, v reflect.Value) (ValidationResult, error) {
	switch v.Kind() {
	case reflect.String:
		if v.String() == "" {
			return ValidationOK, nil
		}
		addr := v.String()
		// do validation by RFC5322
		// http://www.hde.co.jp/rfc/rfc5322.php?page=17

		// screening
		if _, err := mail.ParseAddress(addr); err != nil {
			return ValidationNG, nil
		}

		addrSpec := strings.Split(addr, "@")
		if len(addrSpec) != 2 {
			return ValidationNG, nil
		}
		// check local part
		localPart := addrSpec[0]
		// divided by quoted-string style or dom-atom style
		if match, err := regexp.MatchString(`"[^\t\n\f\r\\]*"`, localPart); err == nil && match { // "\"以外の表示可能文字を認める
			// OK
		} else if match, err := regexp.MatchString(`^([^.\s]+\.)*([^.\s]+)$`, localPart); err != nil || !match { // (hoge.)*hoge
			return ValidationNG, nil
		} else {
			// atext check for local part
			for _, c := range localPart {
				if string(c) == "." {
					// "." is already checked by regexp
					continue
				}
				if !isAtext(c) {
					return ValidationNG, nil
				}
			}
		}
		// check domain part
		domain := addrSpec[1]
		if match, err := regexp.MatchString(`^([^.\s]+\.)*[^.\s]+$`, domain); err != nil || !match { // (hoge.)*hoge
			return ValidationNG, nil
		}
		// atext check for domain part
		for _, c := range domain {
			if string(c) == "." {
				// "." is already checked by regexp
				continue
			}
			if !isAtext(c) {
				return ValidationNG, nil
			}
		}
	default:
		return 0, ErrValidateUnsupportedType
	}

	return ValidationOK, nil
}
90590
func (fw *FirewallSSO) GetCacheTimeout(ctx context.Context) int {
	timeout, err := strconv.ParseInt(fw.CacheTimeout, 10, 32)
	if err != nil {
		log.LoggerWContext(ctx).Debug(fmt.Sprintf("Can't parse timeout '%s' into an int (%s).", fw.CacheTimeout, err))
		return 0
	} else {
		return int(timeout)
	}
}
1209245
func (emailServer *EmailServer) SendEmail(data *SMTPData) error {
	var doc bytes.Buffer
	t := template.New("emailTemplate")
	t, err := t.Parse(SMTPTemplate)
	if err != nil {
		log.Fatal("error trying to parse mail template", err)
		return err
	}
	err = t.Execute(&doc, data)
	if err != nil {
		log.Fatal("error tring to map data to the smtp email template", err)
		return err
	}
	err = emailServer.sendMailFunc(emailServer.host+":"+strconv.Itoa(emailServer.port),
		emailServer.auth,
		data.From,
		[]string{data.To},
		doc.Bytes())
	return err
}
1312923
func ResponseHeaderTimeout(t time.Duration) TransportOption {
	return func(options *transportOptions) {
		options.responseHeaderTimeout = t
	}
}
107557
func (s *PutFileInput) SetEmail(v string) *PutFileInput {
	s.Email = &v
	return s
}
1151463
func (m *MailerImpl) SendMail(to []string, subject, msg string) error {
	m.stats.Inc("SendMail.Attempts", 1)

	for {
		err := m.sendOne(to, subject, msg)
		if err == nil {
			// If the error is nil, we sent the mail without issue. nice!
			break
		} else if err == io.EOF {
			// If the error is an EOF, we should try to reconnect on a backoff
			// schedule, sleeping between attempts.
			m.stats.Inc("SendMail.Errors.EOF", 1)
			m.reconnect()
			// After reconnecting, loop around and try `sendOne` again.
			m.stats.Inc("SendMail.Reconnects", 1)
			continue
		} else if protoErr, ok := err.(*textproto.Error); ok && protoErr.Code == 421 {
			/*
			 *  If the error is an instance of `textproto.Error` with a SMTP error code,
			 *  and that error code is 421 then treat this as a reconnect-able event.
			 *
			 *  The SMTP RFC defines this error code as:
			 *   421 <domain> Service not available, closing transmission channel
			 *   (This may be a reply to any command if the service knows it
			 *   must shut down)
			 *
			 * In practice we see this code being used by our production SMTP server
			 * when the connection has gone idle for too long. For more information
			 * see issue #2249[0].
			 *
			 * [0] - https://github.com/letsencrypt/boulder/issues/2249
			 */
			m.stats.Inc("SendMail.Errors.SMTP.421", 1)
			m.reconnect()
			m.stats.Inc("SendMail.Reconnects", 1)
		} else if protoErr, ok := err.(*textproto.Error); ok && recoverableErrorCodes[protoErr.Code] {
			m.stats.Inc(fmt.Sprintf("SendMail.Errors.SMTP.%d", protoErr.Code), 1)
			return RecoverableSMTPError{fmt.Sprintf("%d: %s", protoErr.Code, protoErr.Msg)}
		} else {
			// If it wasn't an EOF error or a recoverable SMTP error it is unexpected and we
			// return from SendMail() with the error
			m.stats.Inc("SendMail.Errors", 1)
			return err
		}
	}

	m.stats.Inc("SendMail.Successes", 1)
	return nil
}
984964
func Email() string {
	return strings.ToLower(FirstName(RandomGender)+LastName()) + StringNumberExt(1, "", 3) + "@" + randomFrom(jsonData.Domains)
}
1367946
func (this *FcmResponseStatus) IsTimeout() bool {
	if this.StatusCode >= 500 {
		return true
	} else if this.StatusCode == 200 {
		for _, val := range this.Results {
			for k, v := range val {
				if k == error_key && retreyableErrors[v] == true {
					return true
				}
			}
		}
	}

	return false
}
1233576
func (internet Internet) Email(v reflect.Value) (interface{}, error) {
	return internet.email(), nil
}
698661
func (s *Resource) SetEmail(v string) *Resource {
	s.Email = &v
	return s
}
1241474
func (p *Pool) Send(e *Email, timeout time.Duration) (err error) {
	start := time.Now()
	c := p.get(timeout)
	if c == nil {
		return p.failedToGet(start)
	}

	defer func() {
		p.maybeReplace(err, c)
	}()

	recipients, err := addressLists(e.To, e.Cc, e.Bcc)
	if err != nil {
		return
	}

	msg, err := e.Bytes()
	if err != nil {
		return
	}

	from, err := emailOnly(e.From)
	if err != nil {
		return
	}
	if err = c.Mail(from); err != nil {
		return
	}

	for _, recip := range recipients {
		if err = c.Rcpt(recip); err != nil {
			return
		}
	}

	w, err := c.Data()
	if err != nil {
		return
	}
	if _, err = w.Write(msg); err != nil {
		return
	}

	err = w.Close()

	return
}
1300778
func EmailValid(value string, basekey string, mm messages.MessageMap) error {
	if !IsEmail(value) {
		mm.Add(basekey, InvalidEmail)
		return nil
	}
	return nil
}