def validate_id(err, value, source):
    'Tests a manifest UUID value'

    field_name = '<em:id>' if source == 'install.rdf' else 'id'

    id_pattern = re.compile(
        '('
        # UUID format.
        '\{[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}\}'
        '|'
        # "email" format.
        '[a-z0-9-\.\+_]*\@[a-z0-9-\._]+'
        ')',
        re.I)

    err.metadata['id'] = value

    # Must be a valid UUID string.
    if not id_pattern.match(value):
        err.error(
            ('metadata_helpers', '_test_id', 'invalid'),
            'The value of {name} is invalid'.format(name=field_name),
            ['The values supplied for {name} in the {source} file is not a '
             'valid UUID string or email address.'.format(
                 name=field_name, source=source),
             'For help, please consult: '
             'https://developer.mozilla.org/en/install_manifests#id'],
            source)
Tests a manifest UUID value