// DeleteEmails deletes email addresses from authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/users/emails/#delete-email-addresses
344823
func (s *UsersService) DeleteEmails(ctx context.Context, emails []string) (*Response, error) {
	u := "user/emails"
	req, err := s.client.NewRequest("DELETE", u, emails)
	if err != nil {
		return nil, err
	}

	return s.client.Do(ctx, req, nil)
}
593780
func (s *service) EditEmail(reqDTO rest.RequestDTOPutEmail) (resDTO rest.ResponseDTO, error *servicehelper.Error) {
	entity, err := s.repo.FindByEmail(reqDTO.Email)
	if err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("user could not be found"),
			Message: "We could not find any user with the provided email address",
			Param:   "email",
			Code:    servicehelper.NotFound,
		}
	}

	if _, err := s.repo.FindByEmail(reqDTO.NewEmail); err == nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("this email is already used for another account"),
			Message: "Email already used, please chose another email",
			Param:   "new_email",
			Code:    servicehelper.AlreadyExist,
		}
	}

	if err := scrypt.CompareHashAndPassword([]byte(entity.Password), []byte(reqDTO.Password)); err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("invalid password"),
			Message: "We could not authenticate you, please type you password again",
			Param:   "password",
			Code:    servicehelper.BadRequest,
		}
	}
	entity.Email = reqDTO.NewEmail

	if err := s.repo.Update(entity); err != nil {
		return rest.ResponseDTO{}, &servicehelper.Error{
			Detail:  errors.New("could not update user"),
			Message: "We could not update the email of this account, please contact us or try again later",
			Code:    servicehelper.UnexpectedError,
		}
	}

	return createDTOFromEntity(entity), error
}
880614
func GetEmailAddresses(uid int64) ([]*EmailAddress, error) {
	emails := make([]*EmailAddress, 0, 5)
	if err := x.Where("uid=?", uid).Find(&emails); err != nil {
		return nil, err
	}

	u, err := GetUserByID(uid)
	if err != nil {
		return nil, err
	}

	isPrimaryFound := false
	for _, email := range emails {
		if email.Email == u.Email {
			isPrimaryFound = true
			email.IsPrimary = true
		} else {
			email.IsPrimary = false
		}
	}

	// We alway want the primary email address displayed, even if it's not in
	// the emailaddress table (yet).
	if !isPrimaryFound {
		emails = append(emails, &EmailAddress{
			Email:       u.Email,
			IsActivated: true,
			IsPrimary:   true,
		})
	}
	return emails, nil
}
597135
func getPrimaryEmail(client *github.Client, log chronograf.Logger) (string, error) {
	emails, resp, err := client.Users.ListEmails(context.TODO(), nil)
	if err != nil {
		logResponseError(log, resp, err)
		return "", err
	}

	email, err := primaryEmail(emails)
	if err != nil {
		log.Error("Unable to retrieve primary Github email ", err.Error())
		return "", err
	}
	return email, nil
}
301192
func (auth *Auth) DeleteUser(ctx context.Context, userID string) error {
	if len(userID) == 0 {
		return ErrRequireUID
	}

	_, err := auth.client.DeleteAccount(&identitytoolkit.IdentitytoolkitRelyingpartyDeleteAccountRequest{
		LocalId: userID,
	}).Context(ctx).Do()
	if err != nil {
		return err
	}
	return nil
}
583823
func DeleteInactivateUsers() (err error) {
	users := make([]*User, 0, 10)
	if err = x.Where("is_active = ?", false).Find(&users); err != nil {
		return fmt.Errorf("get all inactive users: %v", err)
	}
	// FIXME: should only update authorized_keys file once after all deletions.
	for _, u := range users {
		if err = DeleteUser(u); err != nil {
			// Ignore users that were set inactive by admin.
			if IsErrUserOwnRepos(err) || IsErrUserHasOrgs(err) {
				continue
			}
			return err
		}
	}

	_, err = x.Where("is_activated = ?", false).Delete(new(EmailAddress))
	return err
}
396722
func (m *mailer) resolveEmailAddresses() (emailToRecipientMap, error) {
	result := make(emailToRecipientMap, len(m.destinations))

	for _, r := range m.destinations {
		// Get the email address for the reg ID
		emails, err := emailsForReg(r.id, m.dbMap)
		if err != nil {
			return nil, err
		}

		for _, email := range emails {
			parsedEmail, err := mail.ParseAddress(email)
			if err != nil {
				m.log.Errf("unparseable email for reg ID %d : %q", r.id, email)
				continue
			}
			addr := parsedEmail.Address
			result[addr] = append(result[addr], r)
		}
	}
	return result, nil
}
469987
func (api UsersAPI) DeleteEmailAddress(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	label := mux.Vars(r)["label"]

	userMgr := user.NewManager(r)
	valMgr := validationdb.NewManager(r)

	u, err := userMgr.GetByName(username)
	if err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	email, err := u.GetEmailAddressByLabel(label)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}
	if len(u.EmailAddresses) == 1 {
		http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
		return
	}

	addresses, err := valMgr.GetByUsernameValidatedEmailAddress(username)
	if err != nil {
		log.Error("Failed to get users validated email addresses: ", err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if len(addresses) == 1 && addresses[0].EmailAddress == email.EmailAddress {
		log.Debug("Can't remove last validated email address")
		http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
		return
	}

	if err = userMgr.RemoveEmail(username, label); err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	if err = valMgr.RemoveValidatedEmailAddress(username, email.EmailAddress); err != nil {
		log.Error(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusNoContent)

}
526433
func (s *DeleteFileInput) SetEmail(v string) *DeleteFileInput {
	s.Email = &v
	return s
}
698759
func (b *Broker) DeleteAcls(request *DeleteAclsRequest) (*DeleteAclsResponse, error) {
	response := new(DeleteAclsResponse)

	err := b.sendAndReceive(request, response)
	if err != nil {
		return nil, err
	}

	return response, nil
}
82182
func (e *EmailsService) Delete(params interface{}) (result *Result) {
	result = e.client.delete(e.URL, params, nil)
	return
}
339083
func (b *bundle) GenerateEmail(templateName string, input *EmailTemplateInput) (subject, body string) {
	var err error
	if subject, body, err = b.executeUserTemplate(templateName, input); err != nil {
		// Execution of the user-defined template failed.
		// Fallback to the error template.
		subject, body = b.executeErrorTemplate(templateName, input, err)
	}
	return
}
36910
func (t *Transaction) deleteFieldIndexes(c *Collection, id string) {
	for _, fs := range c.spec.fields {
		switch fs.indexKind {
		case noIndex:
			continue
		case numericIndex, booleanIndex:
			t.deleteNumericOrBooleanIndex(fs, c.spec, id)
		case stringIndex:
			// NOTE: this invokes a lua script which is defined in scripts/delete_string_index.lua
			t.deleteStringIndex(c.Name(), id, fs.redisName)
		}
	}
}
175995
func (maildir *Maildir) DeleteAll() error {
	err := os.RemoveAll(maildir.Path)
	if err != nil {
		return err
	}
	return os.Mkdir(maildir.Path, 0770)
}
787996
func (u *DummyUser) Mailboxes() []Mailbox {
	mailboxes := make([]Mailbox, len(u.mailboxes))
	index := 0
	for _, element := range u.mailboxes {
		mailboxes[index] = element
		index++
	}
	return mailboxes
}
500547
func (m *DummyMailbox) DeleteFlaggedMessages() ([]Message, error) {
	var delIDs []int
	var delMsgs []Message

	// Find messages to be deleted.
	for i, msg := range m.messages {
		if msg.Flags().HasFlags(types.FlagDeleted) {
			delIDs = append(delIDs, i)
			delMsgs = append(delMsgs, msg)
		}
	}

	// Delete message from slice. Run this backward because otherwise it would
	// fail if we have multiple items to remove.
	for x := len(delIDs) - 1; x >= 0; x-- {
		i := delIDs[x]
		// From: https://github.com/golang/go/wiki/SliceTricks
		m.messages, m.messages[len(m.messages)-1] = append(m.messages[:i],
			m.messages[i+1:]...), nil
	}

	// Update sequence numbers.
	for i, msg := range m.messages {
		dmsg := msg.(*DummyMessage)
		dmsg.sequenceNumber = uint32(i) + 1
	}

	return delMsgs, nil
}
1058420
func (client *Client) DeleteRules(args *DeleteRulesArgs) error {
	response := DeleteRulesResponse{}
	err := client.Invoke("DeleteRules", args, &response)
	if err != nil {
		return err
	}
	return err
}