Adding support for email addresses includes in '<' and '>'.

This commit is contained in:
Karl-Heinz Zimmer 2002-10-31 16:30:45 +00:00
parent f1750eee8a
commit e4a6f97d5e

View File

@ -457,16 +457,22 @@ bool warnNoCertificate()
bool isEmailInCertificate( const char* email, const char* fingerprint ) bool isEmailInCertificate( const char* email, const char* fingerprint )
{ {
bool bOk = false; bool bOk = false;
if( fingerprint ){ if( searchEmail && fingerprint ){
GpgmeCtx ctx; GpgmeCtx ctx;
GpgmeError err; GpgmeError err;
GpgmeKey rKey; GpgmeKey rKey;
int UID_idx; int UID_idx;
const char* attr_string; const char* attr_string;
int fprLen = strlen( fingerprint ); const char* email = searchEmail;
int emailLen = strlen( email );
int emailCount = 0; int emailCount = 0;
fprintf( stderr, "gpgmeplug isEmailInCertificate looking for fingerprint %s\n", fingerprint ); if (email && *email == '<'){
++email;
emailLen -= 2;
}
fprintf( stderr, "gpgmeplug isEmailInCertificate looking address %s\nin certificate with fingerprint %s\n", email, fingerprint );
gpgme_new( &ctx ); gpgme_new( &ctx );
gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL ); gpgme_set_protocol( ctx, GPGMEPLUG_PROTOCOL );
@ -478,24 +484,21 @@ bool isEmailInCertificate( const char* email, const char* fingerprint )
if ( GPGME_No_Error == err ) { if ( GPGME_No_Error == err ) {
/* extract email(s) */ /* extract email(s) */
for( UID_idx = 0; for( UID_idx = 0;
(attr_string = gpgme_key_get_string_attr( (attr_string = gpgme_key_get_string_attr(
rKey, GPGME_ATTR_EMAIL, 0, UID_idx ) ); rKey, GPGME_ATTR_EMAIL, 0, UID_idx));
++UID_idx ){ ++UID_idx ){
if (attr_string && *attr_string) { if( !attr_string || !*attr_string )
++emailCount; attr_string = gpgme_key_get_string_attr(
fprintf( stderr, "gpgmeplug isEmailInCertificate found email: %s\n", attr_string ); rKey, GPGME_ATTR_USERID, 0, UID_idx );
if( 0 == strcasecmp(attr_string, email) ){ if( attr_string ){
bOk = true; if( *attr_string == '<' )
break; ++attr_string;
}else{ if( *attr_string ){
attr_string = gpgme_key_get_string_attr( ++emailCount;
rKey, GPGME_ATTR_USERID, 0, UID_idx ); fprintf( stderr, "gpgmeplug isEmailInCertificate found email: %s\n", attr_string );
if (attr_string && *attr_string == '<'){ if( 0 == strncasecmp(attr_string, email, emailLen) ){
++attr_string; bOk = true;
if( 0 == strncasecmp(attr_string, email, fprLen) ){ break;
bOk = true;
break;
}
} }
} }
} }
@ -513,7 +516,10 @@ bool isEmailInCertificate( const char* email, const char* fingerprint )
} }
gpgme_release( ctx ); gpgme_release( ctx );
}else{ }else{
fprintf( stderr, "gpgmeplug isEmailInCertificate called with parameter FINGERPRINT being EMPTY\n" ); if( searchEmail )
fprintf( stderr, "gpgmeplug isEmailInCertificate called with parameter FINGERPRINT being EMPTY\n" );
else
fprintf( stderr, "gpgmeplug isEmailInCertificate called with parameter EMAIL being EMPTY\n" );
} }
return bOk; return bOk;
} }