Get the full name, email address and SMTP information from the user.

def input_identity(interface = TerminalInterface()):
    """Get the full name, email address and SMTP information from the user."""

    while True:
        identity = interface.input_fields("""
           In order to send your files via email, I need to get your name and
           email address you will be using to send the files.""",
           ( 'name', 'Your full name', 'string' ),
           ( 'email', 'Your email address', 'string' ))

        try:
            (localpart, hostname) = identity['email'].split('@')
            break
        except ValueError:
            interface.error("""
                I couldn't understand the email address you entered, please try
                again.""")

    while True:
        # Configure the SMTP information
        smtp_details = interface.input_fields("""
            I need details of the SMTP server used to send email for your email
            address '%s'. These values can be obtained from the administrators of
            your email account.
            
            Most of the time, the default options should suffice if you are
            using a free email provider such as GMail.""" % identity['email'],
            ( 'host', 'The SMTP server hostname', 'string', 'smtp.' + hostname),
            ( 'port', 'The SMTP server port', 'integer', 465),
            ( 'use_ssl', 'Use SSL to connect', 'boolean', True),
            ( 'use_tls', 'Use TLS after connecting', 'boolean', False),
            ( 'use_auth', 'Use a username/password to log in', 'boolean', True)
            )

        if smtp_details['use_auth']:
            credentials = interface.input_fields("""
                I need the username and password you use to log into the SMTP
                server, if you provide a blank password, I'll assume you want me to
                ask you each time I try to send an email for your password. This is
                a more secure option but may be tiresome.""",
                ( 'username', 'Your username', 'string', localpart),
                ( 'password', 'Your password', 'password' ))
            if credentials['password'] == '':
                credentials['password'] = None

            smtp_details['username'] = credentials['username']
            smtp_details['password'] = credentials['password']

        new_identity = Identity(identity['name'], identity['email'], **smtp_details)

        # Ask if we want to send a test email.
        interface.new_section() 
        interface.message("""I can try sending a test email to yourself with
        all the SMTP settings you've given me. This is generally a good idea
        because if we correct any mistakes now, you don't need to correct them
        when you want to send a file.""")
        if interface.input_boolean('Try sending a test email?', default=True):
            if new_identity.send_test_email():
                return new_identity

            interface.message("""Sending the test email failed. You can go back
            and try re-entering your SMTP server details now if you wish.""")
            if not interface.input_boolean('Re-enter SMTP server details', default=True):
                return new_identity