def import_users(self):
        """ save users to local DB """
        self.message('saving users into local DB')

        saved_users = self.saved_admins

        # loop over all extracted unique email addresses
        for email in self.email_set:
            owner = self.users_dict[email].get('owner')

            # if owner is not specified, build username from email
            if owner.strip() == '':
                owner, domain = email.split('@')
                # replace any points with a space
                owner = owner.replace('.', ' ')

            # if owner has a space, assume he specified first and last name
            if ' ' in owner:
                owner_parts = owner.split(' ')
                first_name = owner_parts[0]
                last_name = owner_parts[1]
            else:
                first_name = owner
                last_name = ''

            # username must be slugified otherwise won't get into the DB
            username = slugify(owner)

            # check if user exists first
            try:
                # try looking by email
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                # otherwise init new
                user = User()
                user.username = username
                # generate new password only for new users
                user.password = self.generate_random_password()
                user.is_active = True

            # we'll create one user for each unique email address we've got
            user.first_name = first_name.capitalize()
            user.last_name = last_name.capitalize()
            user.email = email

            # extract date joined from old nodes
            # find the oldest node of this user
            oldest_node = OldNode.objects.filter(email=email).order_by('added')[0]
            user.date_joined = oldest_node.added

            # be sure username is unique
            counter = 1
            original_username = username
            while True:
                # do this check only if user is new
                if not user.pk and User.objects.filter(username=user.username).count() > 0:
                    counter += 1
                    user.username = '%s%d' % (original_username, counter)
                else:
                    break

            try:
                # validate data and save
                user.full_clean()
                user.save(sync_emailaddress=False)
            except Exception:
                # if user already exists use that instance
                if(User.objects.filter(email=email).count() == 1):
                    user = User.objects.get(email=email)
                # otherwise report error
                else:
                    tb = traceback.format_exc()
                    self.message('Could not save user %s, got exception:\n\n%s' % (user.username, tb))
                    continue

            # if we got a user to add
            if user:
                # store id
                self.users_dict[email]['id'] = user.id
                # append to saved users
                saved_users.append(user)
                self.verbose('Saved user %s (%s) with email <%s>' % (user.username, user.get_full_name(), user.email))

            # mark email address as confirmed if feature is enabled
            if EMAIL_CONFIRMATION and EmailAddress.objects.filter(email=user.email).count() is 0:
                try:
                    email_address = EmailAddress(user=user, email=user.email, verified=True, primary=True)
                    email_address.full_clean()
                    email_address.save()
                except Exception:
                    tb = traceback.format_exc()
                    self.message('Could not save email address for user %s, got exception:\n\n%s' % (user.username, tb))

        self.message('saved %d users into local DB' % len(saved_users))
        self.saved_users = saved_users
save users to local DB