⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgprecipientdialogcommon.cpp

📁 可以实现对邮件的加密解密以及签名
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		PGPUInt32	arrIndex;
		
		for( arrIndex = 0; arrIndex < key->numARRKeys; arrIndex++ )
		{
			PGPRecipientKeyARRInfo	*arrInfo;
			
			arrInfo = &key->arrKeys[arrIndex];
			if( IsntNull( arrInfo->key ) )
			{
				PGPRecipientKey		*arrKey 	= arrInfo->key;
				PGPRecipientUser	*arrUser	= arrKey->primaryUser;
				
				pgpAssert( arrKey->isVisible );
				pgpAssert( arrUser->userInfo.arrRefCount != 0 );
				
				if( IsMandatoryARRClass( arrInfo->arrClass ) )
				{
					--arrUser->userInfo.enforcedARRRefCount;
					
					if( recipients->arrEnforcement ==
								kPGPARREnforcement_Strict)
					{
						--arrUser->lockRefCount;
					}
				}
				
				--arrUser->userInfo.arrRefCount;
				if( arrUser->userInfo.arrRefCount == 0 )
				{
					if( ! arrUser->movedManually )
					{
						arrUser->markValue = markValue;
					}
				}
			}
		}
	}
}

	static PGPBoolean
MarkGroupARRsForUserToRecipientMove(
	PGPRecipientsList	*recipients,
	PGPRecipientUser	*group,
	PGPUInt32			markValue,
	PGPBoolean			*markedARRs,
	PGPBoolean			*missingARRs)
{
	PGPBoolean		moveGroup;
	
	pgpAssert( recipients->arrEnforcement != kPGPARREnforcement_None );
	pgpAssert( group->kind == kPGPRecipientUserKind_Group );

	moveGroup 		= TRUE;
	*missingARRs 	= FALSE;
	*markedARRs		= FALSE;
	
	if( group->groupInfo.numARRKeys != 0 )
	{
		PGPBoolean	markARRs = TRUE;
		
		if( group->groupInfo.haveMissingARRs )
		{
			*missingARRs = TRUE;
			
			/*
			** In the strict case, the group cannot be moved because an ARR
			** was not found. In the warn case, we move what we can.
			*/
			
			if( recipients->arrEnforcement == kPGPARREnforcement_Strict )
			{
				moveGroup = FALSE;
				markARRs = FALSE;
			}
		}
		
		if( markARRs )
		{
			PGPUInt32	groupItemIndex;
			
			for( groupItemIndex = 0;
					groupItemIndex < group->groupInfo.numKeys;
						++groupItemIndex )
			{
				PGPGroupItem	item;
				PGPError		err;
				
				err = PGPGetIndGroupItem( recipients->groupSet,
							group->groupInfo.groupID, groupItemIndex, &item );
				pgpAssertNoErr( err );
				if( IsntPGPError( err ) )
				{
					PGPRecipientKey	*key = NULL;

					key = (PGPRecipientKey *) item.userValue;
					if( IsntNull( key ) )
					{
						PGPBoolean	keyMissingARRs;
						
						(void) MarkKeyARRsForUserToRecipientMove(
									recipients,
									key, markValue, markedARRs,
									&keyMissingARRs );
									
						if( keyMissingARRs )
							*missingARRs = TRUE;
					}
				}
			}
		}
	}
	
	return( moveGroup );
}

	static void
MarkGroupARRsForRecipientToUserMove(
	PGPRecipientsList	*recipients,
	PGPRecipientUser	*group,
	PGPUInt32			markValue)
{
	pgpAssert( recipients->arrEnforcement != kPGPARREnforcement_None );
	pgpAssert( group->kind == kPGPRecipientUserKind_Group );

	if( group->groupInfo.numARRKeys != 0 )
	{
		PGPUInt32	groupItemIndex;
		
		for( groupItemIndex = 0; groupItemIndex < group->groupInfo.numKeys;
					++groupItemIndex )
		{
			PGPGroupItem	item;
			PGPError		err;
			
			err = PGPGetIndGroupItem( recipients->groupSet,
						group->groupInfo.groupID, groupItemIndex, &item );
			pgpAssertNoErr( err );
			if( IsntPGPError( err ) )
			{
				PGPRecipientKey	*key = NULL;

				key = (PGPRecipientKey *) item.userValue;
				if( IsntNull( key ) )
				{
					(void) MarkKeyARRsForRecipientToUserMove( recipients,
								key, markValue );
				}
			}
		}
	}
}

	static PGPError
FindARR(
	void				*hwndParent,
	PGPRecipientsList	*recipients,
	PGPKeyDBRef			searchResults,
	PGPKeyID			*keyID,
	PGPBoolean			*haveNewKeys)
{
	PGPContextRef	context;
	PGPError		err;
	PGPFilterRef	filter = kInvalidPGPFilterRef;

	(void) hwndParent;
	
	context=recipients->context;

	err = PGPNewKeyDBObjDataFilter( context,
			kPGPKeyProperty_KeyID,
			keyID, 
			sizeof(PGPKeyID),
			kPGPMatchCriterion_Equal, &filter );

	if( IsntPGPError( err ) &&
			PGPFilterRefIsValid( filter ) )
	{
		PGPKeyDBRef	tempDB = kInvalidPGPKeyDBRef;
					
		err = PGPSearchKeyServerDialog( context,
				recipients->serverCount, recipients->serverList,
				recipients->tlsContext, FALSE, &tempDB,
				PGPOUIKeyServerSearchFilter( context, filter ),
#if PGP_WIN32
				PGPOUIParentWindowHandle(context, (HWND) hwndParent),
#endif
				PGPOLastOption( context ) );

		if( IsntPGPError( err ) && PGPKeyDBRefIsValid( tempDB ) )
		{
			PGPUInt32	numKeys;
						
			err = PGPCountKeysInKeyDB( tempDB, &numKeys );
			if( IsntPGPError( err ) && numKeys > 0 )
			{
				PGPKeySetRef	tempDBKeySet;
							
				*haveNewKeys = TRUE;
							
				err = PGPNewKeySet( tempDB, &tempDBKeySet );
				if( IsntPGPError( err ) )
				{
					err = PGPCopyKeys( tempDBKeySet, searchResults, NULL );
							
					PGPFreeKeySet( tempDBKeySet );
				}
			}
						
			PGPFreeKeyDB( tempDB );
		}
					
		PGPFreeFilter( filter );
	}

	return err;
}


	PGPError
PGPMoveRecipientsARRPrefetch(
	void						*hwndParent,
	PGPRecipientsList			*recipients,
	PGPUInt32					numUsers,
	PGPRecipientUser			**userList)
{
	PGPError				err = kPGPError_NoErr;
	PGPUInt32				userIndex;
	PGPRecipientKey			*curKey;
	PGPRecipientUser		*curUser;
	PGPUInt32				arrIndex;
	PGPRecipientKeyARRInfo	*arrInfo;
	PGPKeyDBRef				searchResults;
	PGPBoolean				haveNewKeys;
	PGPContextRef	context;

	pgpAssert( numUsers > 0 );
	pgpAssert( IsntNull( userList ) );
	
	haveNewKeys=FALSE;

	context=recipients->context;
	err = PGPNewKeyDB( context, &searchResults );

	if(IsntPGPError(err))
	{
		for( userIndex = 0; userIndex < numUsers; userIndex++ )
		{
			curUser = userList[userIndex];
		
			pgpAssert( UserIsVisible( curUser ) );

			if( curUser->lockRefCount > 0 )
			{
				pgpAssert(
					curUser->location == kPGPRecipientUserLocation_RecipientList );
			}
			else if( curUser->kind == kPGPRecipientUserKind_MissingRecipient )
			{
				pgpAssert(
					curUser->location == kPGPRecipientUserLocation_RecipientList );
			}
			else
			{
				if( recipients->arrEnforcement != kPGPARREnforcement_None )
				{
					if( curUser->kind == kPGPRecipientUserKind_Key )
					{
						curKey=(curUser->userInfo.key);

						for( arrIndex = 0; arrIndex < curKey->numARRKeys; arrIndex++ )
						{
							arrInfo = &(curKey->arrKeys[arrIndex]);

							if(arrInfo->keyMissing)
							{
								FindARR(hwndParent,
									recipients,
									searchResults,
									&(arrInfo->keyID),
									&haveNewKeys);
							}
						}
					}
					else
					{
						PGPRecipientUser	*group;
						PGPUInt32	groupItemIndex;

						pgpAssert( curUser->kind ==
										kPGPRecipientUserKind_Group );

						group=curUser;
			
						for( groupItemIndex = 0;
							groupItemIndex < group->groupInfo.numKeys;
							++groupItemIndex )
						{
							PGPGroupItem	item;
							PGPError		err;
				
							err = PGPGetIndGroupItem( recipients->groupSet,
								group->groupInfo.groupID, groupItemIndex, &item );
							pgpAssertNoErr( err );

							if( IsntPGPError( err ) )
							{
								// The key must exist, otherwise it will
								// be searched for later
								if(item.userValue!=NULL)
								{
									curKey = (PGPRecipientKey *) item.userValue;
				
									for( arrIndex = 0; arrIndex < curKey->numARRKeys; arrIndex++ )
									{
										arrInfo = &(curKey->arrKeys[arrIndex]);
			
										if(arrInfo->keyMissing)
										{
											FindARR(hwndParent,
												recipients,
												searchResults,
												&(arrInfo->keyID),
												&haveNewKeys);
										}
									}
								}
							}
						}
					}
				}
			}
		}

		// We have keys, now match with users
		if( IsntPGPError( err ) && haveNewKeys )
		{
			err = AddNewKeys( recipients, searchResults );
		}

		PGPFreeKeyDB( searchResults );
	}
	
	return( err );
}

	PGPError
PGPMoveRecipients(
	PGPRecipientsList			*recipients,
	PGPRecipientUserLocation	destinationList,
	PGPUInt32					numUsers,
	PGPRecipientUser			**userList,
	PGPUInt32					*numMovedUsers,
	PGPBoolean					*movedARRs)
{
	PGPError			err = kPGPError_NoErr;
	PGPUInt32			userIndex;
	PGPUInt32			markValue;
	PGPRecipientKey		*curKey;
	PGPRecipientUser	*curUser;
	
	pgpAssert(	destinationList == kPGPRecipientUserLocation_UserList ||
				destinationList == kPGPRecipientUserLocation_RecipientList );
	pgpAssert( numUsers > 0 );
	pgpAssert( IsntNull( userList ) );
	pgpAssert( IsntNull( numMovedUsers ) );
	
	*numMovedUsers 	= 0;
	*movedARRs		= FALSE;
	
	markValue = GetNextMarkValue();

	/* First pass. Mark items to move and skip/remove invalid items */
	for( userIndex = 0; userIndex < numUsers; userIndex++ )
	{
		curUser = userList[userIndex];
		
		pgpAssert( UserIsVisible( curUser ) );

		if( curUser->lockRefCount > 0 )
		{
			pgpAssert(
				curUser->location == kPGPRecipientUserLocation_RecipientList );
		}
		else if( curUser->kind == kPGPRecipientUserKind_MissingRecipient )
		{
			pgpAssert(
				curUser->location == kPGPRecipientUserLocation_RecipientList );
			
			/* 
			** Missing recipients are never allowed in the user list.
			** Remove from view
			*/
			curUser->location = kPGPRecipientUserLocation_Hidden;
			*numMovedUsers += 1;
		}
		else
		{
			PGPBoolean	moveUser = TRUE;

			if( destinationList == kPGPRecipientUserLocation_RecipientList )
			{
				PGPBoolean	missingARRs = FALSE;
				PGPBoolean	markedARRs 	= FALSE;
				
				if( recipients->arrEnforcement != kPGPARREnforcement_None )
				{
					if( curUser->kind == kPGPRecipientUserKind_Key )
					{
						moveUser = MarkKeyARRsForUserToRecipientMove(
										recipients, curUser->userInfo.key,
										markValue, &markedARRs, &missingARRs );
					}
					else
					{
						pgpAssert( curUser->kind ==
											kPGPRecipientUserKind_Group );

						moveUser = MarkGroupARRsForUserToRecipientMove(
										recipients, curUser,
										markValue, &markedARRs, &missingARRs );
					}
				}

				if( moveUser )
				{
					curUser->markValue 		= markValue;
					curUser->movedManually	= TRUE;
					
					*numMovedUsers += 1;
					
					if( markedARRs )
						*movedARRs = TRUE;
						
					if( missingARRs )
					{
						err = SendUserEvent( recipients,
									kPGPRecipientEvent_MoveUserWarningEvent,
									curUser );
					}
				}
				else
				{
					pgpAssert( ! markedARRs );
					
					err = SendUserEvent( recipients,
									kPGPRecipientEvent_MoveUserFailedEvent,
									curUser );
				}
			}
			else
			{
				if( recipients->arrEnforcement != kPGPARREnforcement_None )
				{
					if( curUser->kind == kPGPRecipientUserKind_Key )
					{
						if( curUser->movedManually )
						{
							MarkKeyARRsForRecipientToUserMove(
										recipients, curUser->userInfo.key,
										markValue );
						}
						else if( curUser->userInfo.enforcedARRRefCount != 0 )
						{
							err = SendUserEvent( recipients,
									kPGPRecipientEvent_MovedARRWarningEvent,
									curUser );
						}
					}
					else
					{
						pgpAssert( curUser->kind ==
											kPGPRecipientUserKind_Group );
					
						MarkGroupARRsForRecipientToUserMove( recipients,
									curUser, markValue );
					}
				}
				
				if( moveUser )
				{
					curUser->markValue 		= markValue;
					curUser->movedManually	= FALSE;

					*numMovedUsers += 1;
				}
			}
		}
		
		if( IsPGPError( err ) )
			break;
	}

	/* Second pass. Move all users with correct mark value */
	curKey = recipients->keys;
	while( IsntNull( curKey ) && IsntPGPError( err ) )
	{
		curUser = curKey->users;
		while( IsntNull( curUser ) )
		{
			if( curUser->markValue == markValue &&
				curUser->location != destinationList )
			{
				curUser->location = destinationList;
				
				err = SendUserEvent( recipients,
							kPGPRecipientEvent_MovedUserEvent, curUser );
				if( IsPGPError( err ) )
					break;
			}
		
			curUser = curUser->nextUser;
		}
		
		curKey = curKey->nextKey;
	}

	curUser = recipients->groups;
	while( IsntNull( curUser ) && IsntPGPError( err ))
	{
		if( curUser->markValue == markValue &&
			curUser->location != destinationList )
		{
			curUser->location = destinationList;
			
			err = SendUserEvent( recipients,
							kPGPRecipientEvent_MovedUserEvent, curUser );
			if( IsPGPError( err ) )
				break;
		}
	
		curUser = curUser->nextUser;
	}
	
	return( err );
}

	static void
pgpFindEmailDomain(const char *emailAddress, char *domain)
{
	char *p = (char *) emailAddress;
	
	if (IsNull(emailAddress))
	{
		strcpy(domain, "\0");
		return;
	}

	while(*p && *p != '@')
		p++;
	if(*p)
	{
		p++;
		strcpy(domain, p);
		p = domain;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -