delete_inv_parts( const char *fname, KBNODE keyblock,
		  u32 *keyid, unsigned int options)
{
    KBNODE node;
    int nvalid=0, uid_seen=0, subkey_seen=0;

    (void)fname;

    for(node=keyblock->next; node; node = node->next ) {
	if( node->pkt->pkttype == PKT_USER_ID ) {
	    uid_seen = 1;
	    if( (node->flag & 2) || !(node->flag & 1) ) {
		if( opt.verbose )
		  {
		    char *p=utf8_to_native(node->pkt->pkt.user_id->name,
					   node->pkt->pkt.user_id->len,0);
		    log_info( _("key %s: skipped user ID \"%s\"\n"),
			      keystr(keyid),p);
		    xfree(p);
		  }
		delete_kbnode( node ); /* the user-id */
		/* and all following packets up to the next user-id */
		while( node->next
		       && node->next->pkt->pkttype != PKT_USER_ID
		       && node->next->pkt->pkttype != PKT_PUBLIC_SUBKEY
		       && node->next->pkt->pkttype != PKT_SECRET_SUBKEY ){
		    delete_kbnode( node->next );
		    node = node->next;
		}
	    }
	    else
		nvalid++;
	}
	else if(    node->pkt->pkttype == PKT_PUBLIC_SUBKEY
		 || node->pkt->pkttype == PKT_SECRET_SUBKEY ) {
	    if( (node->flag & 2) || !(node->flag & 1) ) {
		if( opt.verbose )
		  log_info( _("key %s: skipped subkey\n"),keystr(keyid));

		delete_kbnode( node ); /* the subkey */
		/* and all following signature packets */
		while( node->next
		       && node->next->pkt->pkttype == PKT_SIGNATURE ) {
		    delete_kbnode( node->next );
		    node = node->next;
		}
	    }
	    else
	      subkey_seen = 1;
	}
	else if (node->pkt->pkttype == PKT_SIGNATURE
                && openpgp_pk_test_algo (node->pkt->pkt.signature->pubkey_algo)
		&& node->pkt->pkt.signature->pubkey_algo != PUBKEY_ALGO_RSA )
	    delete_kbnode( node ); /* build_packet() can't handle this */
	else if( node->pkt->pkttype == PKT_SIGNATURE &&
		 !node->pkt->pkt.signature->flags.exportable &&
		 !(options&IMPORT_LOCAL_SIGS) &&
		 !have_secret_key_with_kid (node->pkt->pkt.signature->keyid))
	  {
	    /* here we violate the rfc a bit by still allowing
	     * to import non-exportable signature when we have the
	     * the secret key used to create this signature - it
	     * seems that this makes sense */
	    if(opt.verbose)
	      log_info( _("key %s: non exportable signature"
			  " (class 0x%02X) - skipped\n"),
			keystr(keyid), node->pkt->pkt.signature->sig_class );
	    delete_kbnode( node );
	  }
	else if( node->pkt->pkttype == PKT_SIGNATURE
		 && node->pkt->pkt.signature->sig_class == 0x20 )  {
	    if( uid_seen )
	      {
	        if(opt.verbose)
		  log_info( _("key %s: revocation certificate"
			      " at wrong place - skipped\n"),keystr(keyid));
		delete_kbnode( node );
	      }
	    else {
	      /* If the revocation cert is from a different key than
                 the one we're working on don't check it - it's
                 probably from a revocation key and won't be
                 verifiable with this key anyway. */

	      if(node->pkt->pkt.signature->keyid[0]==keyid[0] &&
		 node->pkt->pkt.signature->keyid[1]==keyid[1])
		{
		  int rc = check_key_signature( keyblock, node, NULL);
		  if( rc )
		    {
		      if(opt.verbose)
			log_info( _("key %s: invalid revocation"
				    " certificate: %s - skipped\n"),
				  keystr(keyid), g10_errstr(rc));
		      delete_kbnode( node );
		    }
		}
	    }
	}
	else if( node->pkt->pkttype == PKT_SIGNATURE &&
		 (node->pkt->pkt.signature->sig_class == 0x18 ||
		  node->pkt->pkt.signature->sig_class == 0x28) &&
		 !subkey_seen )
	  {
	    if(opt.verbose)
	      log_info( _("key %s: subkey signature"
			  " in wrong place - skipped\n"), keystr(keyid));
	    delete_kbnode( node );
	  }
	else if( node->pkt->pkttype == PKT_SIGNATURE
		 && !IS_CERT(node->pkt->pkt.signature))
	  {
	    if(opt.verbose)
	      log_info(_("key %s: unexpected signature class (0x%02X) -"
			 " skipped\n"),keystr(keyid),
		       node->pkt->pkt.signature->sig_class);
	    delete_kbnode(node);
	  }
	else if( (node->flag & 4) ) /* marked for deletion */
	  delete_kbnode( node );
    }

    /* note: because keyblock is the public key, it is never marked
     * for deletion and so keyblock cannot change */
    commit_kbnode( &keyblock );
    return nvalid;
}