'Update account email address.
Called by /prefs/update on the site.'

@validatedForm(VUser(), VModhash(), VVerifyPassword('curpass', fatal=False), email=ValidEmails('email', num=1), verify=VBoolean('verify'), dest=VDestination())
def POST_update_email(self, form, jquery, email, verify, dest):

    if form.has_errors('curpass', errors.WRONG_PASSWORD):
        return
    if ((not form.has_errors('email', errors.BAD_EMAILS)) and email):
        if ((not hasattr(c.user, 'email')) or (c.user.email != email)):
            if c.user.email:
                emailer.email_change_email(c.user)
            c.user.set_email(email)
            c.user.email_verified = None
            c.user._commit()
            Award.take_away('verified_email', c.user)
        if verify:
            if (dest == '/'):
                dest = None
            emailer.verify_email(c.user, dest=dest)
            form.set_inputs(curpass='')
            form.set_text('.status', _('you    should    be    getting    a    verification    email    shortly.'))
        else:
            form.set_text('.status', _('your    email    has    been    updated'))
    if ((not email) and c.user.email and ((errors.NO_EMAILS, 'email') in c.errors)):
        c.errors.remove((errors.NO_EMAILS, 'email'))
        if c.user.email:
            emailer.email_change_email(c.user)
        c.user.set_email('')
        c.user.email_verified = None
        c.user.pref_email_messages = False
        c.user._commit()
        Award.take_away('verified_email', c.user)
        form.set_text('.status', _('your    email    has    been    updated'))
