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

📄 npgpnts.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 5 页
字号:
											us_LEN_ITEMNM, &bid_itm, NULL, 
											&bid_ctnt, NULL)) && 
											ERR( us_err) != ERR_ITEM_NOT_FOUND)
			return us_err;
	} while (!us_err);

	//if we didn't finish finding everything out by querying _object_ names, 
	//	traverse the rich-text field itself to check whether the _file_ names 
	//	(the ultimate word) in any attachment hotspots can add something...
	if (ps_hasPgpAtchmt && !f_hasPgpAtchmt || ps_hasRtfObj && !f_hasRtfObj)	{
		RtfContext  t_rtCtx;
		RtfCursor  t_crsr;
		const char * pc_fileNm, * pc;

		//initialize contextual information about the specified rich-text field
		if (us_err = eus_InitializeRtfContext( h_NOTE, pc_ITMNM_RTF, &t_crsr, 
																	&t_rtCtx))
			return us_err;

		//advance the rich-text cursor to the next file-attachment hotspot, 
		//	which (though unlikely) may be the first CD record 
		if (!ef_CursorToAttachmentHotspot( &t_crsr, &t_rtCtx, FALSE, NULL, 
														NULL, &pc_fileNm))	{
			ef_FreeRtfContext( &t_rtCtx);
			return !eus_SUCCESS;
		}

		//loop until either no further file-attachment hotspots exist in the 
		//	rich-text field (or until we've determined the information 
		//	requested by caller)
		while (t_crsr.puc_location)	{
			//if we didn't know of it before and just now hit on the special 
			//	rich-text object...
			if (ps_hasRtfObj && !f_hasRtfObj && stricmp( pc_fileNm, 
											mpc_fileNmPgpRtf) == ei_SAME)	{
				//if caller wants to know whether the object is present, note 
				//	that it is and break out of the loop if there's nothing 
				//	left to find out
				if (ps_hasRtfObj)	{
					f_hasRtfObj = TRUE;
					if (!ps_hasPgpAtchmt || f_hasPgpAtchmt)
						break;
				}
			//Else if caller wants to know whether regular PGP-encoded 
			//	attachments are present and none have been located yet...
			}else if (ps_hasPgpAtchmt && !f_hasPgpAtchmt)	{
				//if we've hit on one, note that it is and break out of the 
				//	loop if there's nothing left to find out
				pc = pc_fileNm + strlen( pc_fileNm);
				if (stricmp( pc - mui_LEN_ARMOR_EXT_ASC, 
										mpc_PGP_ARMOR_EXT_ASC) == ei_SAME || 
										stricmp( pc - mui_LEN_ARMOR_EXT_PGP, 
										mpc_PGP_ARMOR_EXT_PGP) == ei_SAME)	{
					f_hasPgpAtchmt = TRUE;
					if (!ps_hasRtfObj || f_hasRtfObj)
						break;
				} //if (stricmp( pc - mui_LEN_ARMOR_EXT_ASC
			} //if (stricmp( pc_fileNm, mpc_fileNmPgpRtf)

			//advance the rich-text cursor to the next file-attachment hotspot
			if (f_fail = !ef_CursorToAttachmentHotspot( &t_crsr, &t_rtCtx, 
												FALSE, NULL, NULL, &pc_fileNm))
				break;
		} //while (t_crsr.puc_location)

		//free the contextual information about the rich-text field
		ef_FreeRtfContext( &t_rtCtx);

		if (f_fail)
			return !eus_SUCCESS;
	} //if (ps_hasPgpAtchmt || ps_hasRtfObj &&

	//inform caller of any positive findings
	if (f_hasPgpAtchmt)
		*ps_hasPgpAtchmt = ms_VB_TRUE;
	if (f_hasRtfObj)
		*ps_hasRtfObj = ms_VB_TRUE;

	return eus_SUCCESS;
} //xus_TestNoteForPgpArmor(


/** us_LocatePgpRtfAttachment( ***


--- parameters & return ----

RETURN: 

--- revision history -------
9/6/02 PR: logic performance enhancement, minor token renaming, listing format 
	adjustment

9/16/00 PR: token renaming
9/12/99 PR: added smart differentiation between compressed & non-compressed 
	files
1/30/99 PR: created			*/
//DOC!!
static STATUS us_LocatePgpRtfAttachment( RtfCursor  t_crsr, 
											const RtfContext *const  pt_RT_CTX, 
											NOTEHANDLE  h_NOTE, 
											DWORD *const  pul_objId, 
											DWORD *const  pul_size, 
											BLOCKID *const  pbid_itm)	{
	const char * pc_objNm, * pc_fileNm;
	BOOL  f_Match = FALSE, f_compressed;
	DWORD  ul_objId;
	STATUS  us_err;

	_ASSERTE( t_crsr.puc_location && t_crsr.us_recLength && pul_objId && 
														pul_size && pbid_itm);

	*pul_objId = *pul_size = NULL;
	*pbid_itm = ebid_NULLBLOCKID;

	if (!NSFNoteHasObjects( h_NOTE, NULL))
		return eus_SUCCESS;

	//advance the rich-text cursor to the next file-attachment hotspot, which 
	//	(though unlikely) may be the first CD record 
	if (!ef_CursorToAttachmentHotspot( &t_crsr, pt_RT_CTX, FALSE, NULL, 
														&pc_objNm, &pc_fileNm))
		return !eus_SUCCESS;

	//Loop either until no further file-attachment hotspots exist in the 
	//	rich-text field or until the PGP rich-text attachment is found. We 
	//	search for the special attachment using this technique first in case 
	//	more than one version of the PGP rich-text attachment exists on the 
	//	document. If there is more than one, we should default to the one 
	//	actually present in the RTF because that one must be the most recent 
	//	version.
	if (!*mpc_fileNmPgpRtf)
		strcat( strcpy( mpc_fileNmPgpRtf, mpc_ROOTFILENM_PGP_RTF), 
														mpc_PGP_ARMOR_EXT_ASC);
	while (t_crsr.puc_location)	{
		//A file-attachment hotspot must have been found, so determine whether 
		//	the "original" name of the attachment as stored in the hotspot 
		//	matches the filename we're after. If we have found a match, break 
		//	out of this loop to move on to the next stage
		if (f_Match = stricmp( pc_fileNm, mpc_fileNmPgpRtf) == ei_SAME)
			break;

		//advance the rich-text cursor to the next file-attachment hotspot
		if (!ef_CursorToAttachmentHotspot( &t_crsr, pt_RT_CTX, FALSE, NULL, 
														&pc_objNm, &pc_fileNm))
			return !eus_SUCCESS;
	} //while (t_crsr.puc_location)

	//Get the necessary location info for the caller to use in accessing the 
	//	attachment. If we didn't find a corresponding attachment hotspot in the 
	//	rich-text field, we will accept a properly named attachment not 
	//	incorporated.
	if (!f_Match)
		pc_objNm = mpc_fileNmPgpRtf;
	if (us_err = eus_getAttachmentInfo( h_NOTE, NULL, pc_objNm, &ul_objId, 
													pul_size, &f_compressed, 
													NULL, pbid_itm, NULL))
		return us_err;

	//if the file is not compressed, set the object ID return variable, thus 
	//	signifying that the file is uncompressed (important later to 
	//	eus_getObjectContentsInBuffer()
	if (!f_compressed)
		*pul_objId = ul_objId;

	return us_err;
} //us_LocatePgpRtfAttachment(


/** xus_SetupPgpRtfObj( ***
Purpose is to work the special PGP rich-text attachment and its associated 
rich-text hotspot associated into a user- and system-friendly state. 
User-friendly by making it hidden and system-friendly by having it behave as 
needed (even if that means getting rid of it).

--- parameter & return ----
h_NOTE: the handle to the note containing the hotspots to be converted
pc_ITMNM_RTF: the name of the message-body rich-text field
RETURN:
	eus_SUCCESS if no errors occurred
	eus_ERR_INVLD_ARG if any input parameter is obviously invalid
	the Notes API error code otherwise

--- revision history ------
9/6/02 PR: minor logic adjustments for performance and in support of signature 
	change to eus_getAttachmentInfo, listing format adjustment, token renaming, 
	minor documentation adjustment

9/16/00 PR
+ updated so that attachments with either PGP extension are supported
+ changed name of function to better reflect its work
+ token renaming

1/29/99 PR: created			*/
STATUS xus_SetupPgpRtfObj( const NOTEHANDLE  h_NOTE, 
								char  pc_ITMNM_RTF[])	{
	static const char  pc_NOTES_MAIL_MATCH[] = "Lotus Notes Release";
	static char  pc_ITMNM_MAILER[] = "$Mailer";		//MAIL_MAILER_ITEM not 
													//	defined in 4.5.1 API

	RtfContext  t_rtCtx, t_rtCtxAttachPgrph;
	RtfCursor  t_crsr;
	RtfSpan  t_span;
	const char * pc_fileNm;
	char * pc_objNm, * pc;
	BOOL  f_utilRtfStarted = FALSE, f_mailedByNotes = TRUE, f_fail;
	BLOCKID  bid_ctnts, bid_itm;
	STATUS  us_err;

	if (!( h_NOTE && pc_ITMNM_RTF))
		return eus_ERR_INVLD_ARG;

	//if there aren't any attachments, short-circuit with success
	if (!NSFNoteHasObjects( h_NOTE, NULL))
		return eus_SUCCESS;

	//initialize resources associated with the rich-text handling we're going 
	//	to do
	if (us_err = eus_InitializeRtfContext( h_NOTE, pc_ITMNM_RTF, &t_crsr, 
																	&t_rtCtx))
		return us_err;

	//advance the rich-text cursor to the next file-attachment hotspot, which 
	//	(though unlikely) may be the first CD record
	if (f_fail = !ef_CursorToAttachmentHotspot( &t_crsr, &t_rtCtx, FALSE, 
												&t_span, &pc_objNm, &pc_fileNm))
		goto errJump;

	//search for a special PGP-encoded rich-text attachment hotspot in the 
	//	rich-text field
	if (!*mpc_fileNmPgpRtf)
		strcat( strcpy( mpc_fileNmPgpRtf, mpc_ROOTFILENM_PGP_RTF), 
														mpc_PGP_ARMOR_EXT_ASC);
	while (t_crsr.puc_location && stricmp( pc_fileNm, mpc_fileNmPgpRtf) != 
																		ei_SAME)
		if (f_fail = !ef_CursorToAttachmentHotspot( &t_crsr, &t_rtCtx, FALSE, 
												&t_span, &pc_objNm, &pc_fileNm))
			goto errJump;

	//determine whether the message was mailed by Notes
	if (us_err = eus_AttemptCopyTextItemContent( h_NOTE, pc_ITMNM_MAILER, 
															NULL, &pc, NULL))
		goto errJump;
	if (pc)	{
		f_mailedByNotes = strnicmp( pc, pc_NOTES_MAIL_MATCH, sizeof( 
										pc_NOTES_MAIL_MATCH) - 1) == ei_SAME;
		free( pc);
	}

	//if a rich-text hotspot was found associated with the special rich-text 
	//	attachment...
	if (t_crsr.puc_location)	{
		//remove current hotspot because one way or another it's got to go
		if (us_err = eus_RemoveRtSpan( &t_span, &t_rtCtx))
			goto errJump;

		//if the message wasn't mailed by Notes...
		if (!f_mailedByNotes)	{
			//delete the attachment associated with the removed 
			//	special-attachment hotspot since it's very unlikely that its 
			//	contents are valid (e.g. the attachment originated in a Notes 
			//	plug-in client-sent e-mail to a non-Notes e-mail client, then 
			//	the attachment was forwarded on to a plug-in-enabled Notes 
			//	client, so the attachment contains the contents of the original 
			//	message, not the forwarded message, not a good thing)
			if (us_err = eus_DeleteAttachment( h_NOTE, pc_objNm, NULL))
				if (ERR( us_err) != ERR_ITEM_NOT_FOUND)
					goto errJump;
				else
					us_err = eus_SUCCESS;
		//else eliminate the possibility of the special PGP rich-text 
		//	attachment being inherited into documents created via the @Command( 
		//	[MailForward]) mechanism or via forms having the "Inherit entire 
		//	selected document into the rich-text field ... as rich-text" 
		//	setting...
		}else	{
			//initialize the rich-text hidden paragraph we will use to store the 
			//	special object
			if (us_err = us_SetupRtfAttachParagraph( h_NOTE, 
												&t_rtCtxAttachPgrph, pc_objNm))
				goto errJump;
			f_utilRtfStarted = TRUE;

			//Append the special ending hidden-paragraph rich-text to the our 
			//	adjusted main rich-text field. Since both above-mentioned 
			//	mechanisms ignore whatever's in hidden paragraphs, this method 
			//	avoids the inheritance issue and is cosmetically attractive to boot.
			if (us_err = eus_AppendItemsToRtf( &t_rtCtxAttachPgrph, &t_rtCtx))
				goto errJump;
		} //if (f_mailedByNotes)

		//commit the updated rich-text field to the note, replacing the current 
		//	actual rich-text content
		us_err = eus_CommitChangedRtf( h_NOTE, pc_ITMNM_RTF, &t_rtCtx);
	//Else if the special PGP rich-text attachment is present without a 
	//	corresponding hotspot, the message probably came into the system via 
	//	the client POP3/IMAP4 "Direct to Internet" mechanism...
	}else if (us_err = eus_getAttachmentInfo( h_NOTE, NULL, mpc_fileNmPgpRtf, 
														NULL, NULL, NULL, NULL, 
														&bid_itm, &bid_ctnts))
		goto errJump;
	else if (bid_ctnts.pool)	{
		//if the message was put in the mail by Notes...
		if (f_mailedByNotes)	{
			//Change the "host type" of the special attachment to a type that 
			//	Notes will not inherit into documents created via the 
			//	mechanisms described above. This is an acceptable thing to do 
			//	for _received_ messages, since this message won't be going 
			//	through a SMTP MTA anymore, so we don't care about the fact 
			//	that the MTA will not forward attachments with the STREAM host 
			//	type. Another nice by-product of doing this is that the 
			//	attachment will not show up "below the line" on the message 
			//	(i.e. it'll be hidden)
			FILEOBJECT *const  ptfo = (FILEOBJECT *) (OSLockBlock( WORD, 
																bid_ctnts) + 1);

			ptfo->HostType = HOST_STREAM;
			OSUnlockBlock( bid_ctnts);
		//else delete the special attachment since it's very unlikely that 
		//	its contents remain valid (e.g. the attachment originated in a 
		//	Notes plug-in client-sent e-mail to a non-Notes e-mail client, then 
		//	the attachment was forwarded on to a plug-in-enabled Notes client, 
		//	so the attachment contains the contents of the original message, 
		//	not the forwarded message, not a good thing)
		}else
			us_err = NSFNoteDetachFile( h_NOTE, bid_itm);
	} //if (us_err = eus_getAttachmentInfo(

errJump:
	if ((us_err || f_fail) && f_utilRtfStarted)
		ef_FreeRtfContext( &t_rtCtxAttachPgrph);
	ef_FreeRtfContext( &t_rtCtx);

	return us_err + f_fail;
} //xus_SetupPgpRtfObj(


/** DllMain( ***
Win32 entry point for loading and unloading this DLL.  We use the unload 
event to free statically allocated resources.

--- parameters & return ---

⌨️ 快捷键说明

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