Ejemplo n.º 1
0
    def parseAddress(self, addr, fieldname="Maintainer"):
        """Parse an address, using the policy to decide if we should add a
        non-existent person or not.

        Raise an UploadError if the parsing of the maintainer string fails
        for any reason, or if the email address then cannot be found within
        the launchpad database.

        Return a dict containing the rfc822 and rfc2047 formatted forms of
        the address, the person's name, email address and person record within
        the launchpad database.
        """
        try:
            (rfc822, rfc2047, name,
             email) = safe_fix_maintainer(addr, fieldname)
        except ParseMaintError as error:
            raise UploadError(str(error))

        person = getUtility(IPersonSet).getByEmail(email)
        if person and person.private:
            # Private teams can not be maintainers.
            raise UploadError("Invalid Maintainer.")

        if person is None and self.policy.create_people:
            package = self._dict['Source']
            version = self._dict['Version']
            if self.policy.distroseries and self.policy.pocket:
                policy_suite = (
                    '%s/%s' %
                    (self.policy.distroseries.name, self.policy.pocket.name))
            else:
                policy_suite = '(unknown)'
            try:
                person = getUtility(IPersonSet).ensurePerson(
                    email,
                    name,
                    PersonCreationRationale.SOURCEPACKAGEUPLOAD,
                    comment=('when the %s_%s package was uploaded to %s' %
                             (package, version, policy_suite)))
            except InvalidEmailAddress:
                self.logger.info("Invalid email address: '%s'", email)
                person = None

        if person is None:
            raise UploadError("Unable to identify '%s':<%s> in launchpad" %
                              (name, email))

        return {
            "rfc822": rfc822,
            "rfc2047": rfc2047,
            "name": name,
            "email": email,
            "person": person,
        }
Ejemplo n.º 2
0
    def parseAddress(self, addr, fieldname="Maintainer"):
        """Parse an address, using the policy to decide if we should add a
        non-existent person or not.

        Raise an UploadError if the parsing of the maintainer string fails
        for any reason, or if the email address then cannot be found within
        the launchpad database.

        Return a dict containing the rfc822 and rfc2047 formatted forms of
        the address, the person's name, email address and person record within
        the launchpad database.
        """
        try:
            (rfc822, rfc2047, name, email) = safe_fix_maintainer(
                addr, fieldname)
        except ParseMaintError as error:
            raise UploadError(str(error))

        person = getUtility(IPersonSet).getByEmail(email)
        if person and person.private:
            # Private teams can not be maintainers.
            raise UploadError("Invalid Maintainer.")

        if person is None and self.policy.create_people:
            package = self._dict['Source']
            version = self._dict['Version']
            if self.policy.distroseries and self.policy.pocket:
                policy_suite = ('%s/%s' % (self.policy.distroseries.name,
                                           self.policy.pocket.name))
            else:
                policy_suite = '(unknown)'
            try:
                person = getUtility(IPersonSet).ensurePerson(
                    email, name, PersonCreationRationale.SOURCEPACKAGEUPLOAD,
                    comment=('when the %s_%s package was uploaded to %s'
                             % (package, version, policy_suite)))
            except InvalidEmailAddress:
                self.logger.info("Invalid email address: '%s'", email)
                person = None

        if person is None:
            raise UploadError("Unable to identify '%s':<%s> in launchpad"
                              % (name, email))

        return {
            "rfc822": rfc822,
            "rfc2047": rfc2047,
            "name": name,
            "email": email,
            "person": person,
            }
Ejemplo n.º 3
0
def email_to_person(fullemail):
    """Return an `IPerson` given an RFC2047 email address.

    :param fullemail: Potential email address.
    :return: `IPerson` with the given email address.  None if there
        isn't one, or if `fullemail` isn't a proper email address.
    """
    if not fullemail:
        return None

    try:
        # The 2nd arg to s_f_m() doesn't matter as it won't fail since every-
        # thing will have already parsed at this point.
        rfc822, rfc2047, name, email = safe_fix_maintainer(fullemail, "email")
        return getUtility(IPersonSet).getByEmail(email)
    except ParseMaintError:
        return None
Ejemplo n.º 4
0
def email_to_person(fullemail):
    """Return an `IPerson` given an RFC2047 email address.

    :param fullemail: Potential email address.
    :return: `IPerson` with the given email address.  None if there
        isn't one, or if `fullemail` isn't a proper email address.
    """
    if not fullemail:
        return None

    try:
        # The 2nd arg to s_f_m() doesn't matter as it won't fail since every-
        # thing will have already parsed at this point.
        rfc822, rfc2047, name, email = safe_fix_maintainer(fullemail, "email")
        return getUtility(IPersonSet).getByEmail(email)
    except ParseMaintError:
        return None