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

📄 npgpnts.c

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 C
📖 第 1 页 / 共 5 页
字号:
		goto errJump;

	//commit to note the changes made to the rich-text field
	if (us_err = eus_CommitChangedRtf( h_NOTE, pc_ITMNM_RTF, pt_rtfContext))
		goto errJump;

	//remove the item used by the note to point to the special attachment
	us_err = NSFNoteDetachFile( h_NOTE, bid_OBJ_ITEM);

errJump:
	if (pc_output)
		e_FreePgpMem( pc_output);

	return us_err + i_err;
} //i_PgpDecodeUsingRichTextObj(


/** us_ReplaceRichAsciiLines( ***
Replaces the first matching text block in the given rich-text field with the 
given null-terminated replacement text block.

--- parameters & return ----
pc_CTNT: Address of a null-terminated ASCII-text version of the specified 
	rich-text field. This input allows procedure to find the correct occurrence 
	of pc_BLK within the rich-text field.
pc_BLK: Address of the beginning of the block of CRLF-delimited text lines in 
	the rich-text field that is to be replaced. (Address must therefore fall 
	within the pc_CTNT string.) The first line of the block is used to search 
	for a matching position within the rich-text field.
ul_LEN_BLK: Length of text to be replaced. Value must therefore not offset 
	beyond the end of the pc_CTNT string.
pc_REPL: Address of null-terminated text block to replace the block within the 
	rich-text field identified by pc_BLK. If necessary, a CRLF will be appended 
	to maintain the concept of replacing _lines_.
pt_crsr: Input & Output. Address of rich-text cursor from which to start 
	searching for the specified text block (pc_BLK) within the rich-text field. 
	On successful return from call, cursor is eset to point to the CD record 
	following the replacement.
pt_rtCtx: Input & Output. Address of opaque structure describing the current 
	state of the rich-text field involved in the operation.
RETURN: eus_SUCCESS if no error occured; the Notes API error code otherwise

--- revision history -------
9/6/02 PR
+ logic enhancement to allow output of rich-text position following the 
  replacement block
+ improved procedure name, much token renaming, improved call-safety checking
+ completed standard documentation
+ listing format adjustment

7/16/99 PR: changed default nullification of end-cursor member of the RtfSpan 
	structure passed to eus_ReplaceRtfSpanText() to use the standard 
	null-cursor flag
11/23/98 PR: created		*/
static STATUS us_ReplaceRichAsciiLines( const char *const  pc_CTNT, 
										const char *const  pc_BLK, 
										const DWORD  ul_LEN_BLK, 
										const char *const  pc_REPL, 
										RtfCursor *const  pt_crsr, 
										RtfContext *const  pt_rtCtx)	{
	long  l;
	const char * pc;
	char * pc_cmp = NULL, * pc_ = NULL;
	WORD  us_offst, us = NULL;
	UINT  ui;
	RtfSpan  t_rtfSpn;
	STATUS  us_err;
	BOOL  f_fail;
	int  i_err = NULL;

	_ASSERTE( pc_CTNT && pc_BLK && ul_LEN_BLK && pc_BLK >= pc_CTNT && pc_BLK + 
								ul_LEN_BLK <= pc_CTNT + strlen( pc_CTNT) && 
								pc_REPL && pt_crsr->puc_location && pt_rtCtx);

	//Note the first line of the text block to be replaced. This will be used 
	//	to find the start of this block within the actual rich-text field.
	if (f_fail = !(BOOL) (pc_cmp = malloc( l = strstr( pc_BLK, epc_CRLF) - 
																pc_BLK + 1)))
		goto errJump;
	memcpy( pc_cmp, pc_BLK, l - 1);
	pc_cmp[ l - 1] = NULL;

	//starting from the caller-specified position in the rich-text field, loop 
	//	to the start of the text block to be replaced...
	pc = pc_CTNT - 1;
	do	{
		//locate the next instance of the sought-for line in the rich-text field
		if (f_fail = !ef_CursorToStringStart( pc_cmp, TRUE, *pt_crsr, us, 
												pt_rtCtx, pt_crsr, &us_offst))
			goto errJump;
		if (f_fail = !(BOOL) pt_crsr->puc_location)
			goto errJump;

		//move to the corresponding line in the regular-text version of the 
		//	content
		if (f_fail = !(BOOL) (pc = strstr( pc + 1, pc_cmp)))
			goto errJump;

		//if the line we found isn't the actual beginning of the sought-for 
		//	text block, loop for a further pass
		us = us_offst + 1;
	} while (pc < pc_BLK);

	//if necessary, tack a CRLF onto the replacement text to maintain the 
	//	concept of replacing lines with lines
	if (strcmp( pc_REPL + (ui = strlen( pc_REPL)) - ei_LEN_CRLF, epc_CRLF) != 
																ei_SAME)	{
		pc_ = malloc( ui + ei_LEN_CRLF + 1);
		strcat( strcpy( pc_, pc_REPL), epc_CRLF);
	}

	//replace the ASCII text block identified within the rich-text field with 
	//	the replacement content
	t_rtfSpn.t_crsrBgin = *pt_crsr;
	t_rtfSpn.us_offstBgin = us_offst;
	t_rtfSpn.t_crsrEnd.puc_location = NULL;
	us_err = eus_ReplaceRtfSpanText( &t_rtfSpn, ul_LEN_BLK, TRUE, pc_ ? pc_ : 
															pc_REPL, pt_rtCtx);
	if (pc_)
		free( pc_);
	if (us_err)
		goto errJump;

	//note for caller the position of the CD record following the replacement 
	//	text
	*pt_crsr = t_rtfSpn.t_crsrEnd;
	us_err = eus_CursorAdvance( pt_crsr, pt_rtCtx);

errJump:
	if (pc_cmp)
		free( pc_cmp);

	return us_err ? us_err : i_err || f_fail ? !eus_SUCCESS : eus_SUCCESS;
} //us_ReplaceRichAsciiLines(


/** xus_TestNoteForPgpAscii( ***
This exported interface allows the note passed in to be inspected for 
PGP-encoded ASCII text in the message body (rich-text field).

--- parameters & return ----
h_NOTE: the handle to the note to be inspected for PGP-encoded ASCII
pc_ITMNM_RTF: the name of the message-body rich-text field
pus_hasPgpAscii: flag telling whether encoded ASCII was found (TRUE) or not 
	(FALSE)
RETURN:
	eus_SUCCESS if no errors occurred
	eus_ERR_INVLD_ARG if any passed-in parameter is obviously invalid
	the Notes API error code otherwise

--- revision history -------
9/6/02 PR
+ logic enhancement to support high-ASCII (international) characters in 
  attachment handling
+ minor documentation adjustment, listing format adjustment, token renaming, 
  exception-handling adjustment

11/18/98 PR: created		*/
STATUS xus_TestNoteForPgpAscii( NOTEHANDLE  h_NOTE, 
								char  pc_ITMNM_RTF[], 
								short *const  ps_hasPgpAscii)	{
	RtfCursor  t_crsr;
	RtfContext  t_rtCtx;
	char * pc_ctnt = NULL, * pc_ctntOs;
	ULONG  ul;
	BOOL  f_hasPgpAscii, f_failure;
	STATUS  us_err;
	int  i_err = NULL;

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

	//set default that PGP-encoded ASCII content was not found
	*ps_hasPgpAscii = ms_VB_FALSE;

	//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;

	//if we can't get the textual content of the rich-text field or if that 
	//	content is too short to contain a PGP block, short-circuit
	if ( (f_failure = eul_ERR_FAILURE == (ul = eul_GetRtfText( &t_rtCtx, 
											NULL, TRUE, &pc_ctnt))) || ul <= 1)
		goto errJump;

	//if PGP-encoded ASCII is included in the content, indicate this to caller
	if (!(pc_ctntOs = malloc( ul)))	{
		i_err = -11999;		//kPGPError_OutOfMemory
		goto errJump;
	}
	if (OSTranslate( OS_TRANSLATE_LMBCS_TO_NATIVE, pc_ctnt, (WORD) (ul - 1), 
													pc_ctntOs, (WORD) ul))	{
		if (!( i_err = ei_TestForPgpAscii( pc_ctntOs, &f_hasPgpAscii)) && 
																f_hasPgpAscii)
			*ps_hasPgpAscii = ms_VB_TRUE;
	}else
		i_err = !eus_SUCCESS;
	free( pc_ctntOs);

errJump:
	//as necessary, free resources allocated during this procedure
	if (pc_ctnt)
		free( pc_ctnt);
	ef_FreeRtfContext( &t_rtCtx);

	return f_failure || i_err ? !eus_SUCCESS : eus_SUCCESS;
} //xus_TestNoteForPgpAscii(


/** xus_TestNoteForPgpArmor( ***
Determine whether PGP-encoded file attachments occur in the specified rich-text 
field, providing differentiation between the special PGP-encoded rich-text 
object and regular encoded attachments.

--- parameters & return ----
h_NOTE: the handle to the note containing the specified rich-text field
pc_ITMNM_RTF: pointer to a string telling the name of the rich-text field to be 
	processed
ps_hasPgpAtchmt: Provisionally Optional Output. Address of the Visual-Basic 
	type flag in which to return whether any PGP-encoded file attachemnts were 
	found apart from the special rich-text attachment. If null, output will be 
	suppressed. At least one output must be requested within call.
ps_hasRtfObj: Provisionally Optional Output. Address of the Visual-Basic type 
	flag in which to return wehter the special PGP-encoded rich-text attachment 
	is present on the given note. If null, output will be suppressed. At least 
	one output must be requested within call.
RETURN:
	eus_ERR_INVLD_ARG if any input is obviously invalid
	!eus_SUCCESS if a rich-text cursoring error occurred
	eus_SUCCESS if no error occured
	the Notes API error code otherwise

--- revision history -------
9/6/02 PR
+ fixed variable-initialization bug
+ fixed bug that could give a false-positive when deciding if an attachment was 
  the special PGP-encoded rich-text attachment
+ listing format adjustment, token renaming

9/16/00 PR
+ added functionality to differentiate between the special rich-text object and 
  other PGP-encoded attachments; required a signature change
+ updated so that attachments with either PGP extension are supported
+ logic streamlining

11/12/98 PR: created		*/
STATUS xus_TestNoteForPgpArmor( const NOTEHANDLE  h_NOTE, 
								char  pc_ITMNM_RTF[], 
								short *const  ps_hasPgpAtchmt, 
								short *const  ps_hasRtfObj)	{
	static UINT  ui_lenFileNmPgpRtf;

	const WORD  us_LEN_ITEMNM = strlen( epc_ITEMNM_STANDARD_ATTACH);

	BLOCKID  bid_itm, bid_ctnt, bid_prvItm;
	const BYTE * puc;
	const FILEOBJECT * pflo;
	BOOL  f_hasRtfObj = FALSE, f_hasPgpAtchmt = FALSE, f_fail = FALSE;
	STATUS  us_err;

	if (!( h_NOTE && pc_ITMNM_RTF && (ps_hasPgpAtchmt || ps_hasRtfObj)))
		return eus_ERR_INVLD_ARG;

	if (ps_hasPgpAtchmt)
		*ps_hasPgpAtchmt = ms_VB_FALSE;
	if (ps_hasRtfObj)
		*ps_hasRtfObj = ms_VB_FALSE;

	//if it hasn't been done already, construct the filename of the special PGP 
	//	rich-text object
	if (!*mpc_fileNmPgpRtf)	{
		strcat( strcpy( mpc_fileNmPgpRtf, mpc_ROOTFILENM_PGP_RTF), 
														mpc_PGP_ARMOR_EXT_ASC);	
		ui_lenFileNmPgpRtf = strlen( mpc_fileNmPgpRtf);
	}

	//Get a handle on the first attachment item present in the note. If no such 
	//	item is present, we've determined that the answer to all the caller's 
	//	questions is negative, so short-circuit with success.
	if (us_err = NSFItemInfo( h_NOTE, epc_ITEMNM_STANDARD_ATTACH, 
													us_LEN_ITEMNM, &bid_itm, 
													NULL, &bid_ctnt, NULL))
		if (ERR( us_err) == ERR_ITEM_NOT_FOUND)
			return eus_SUCCESS;
		else
			return us_err;

	//cycle through the attachment items (and thus object names) until we've 
	//	gleaned as much information useful to our purpose as we can...
	do	{
		//if the object name given by the item matches the name of the special 
		//	PGP rich-text object...
		pflo = (FILEOBJECT *) (OSLockBlock( WORD, bid_ctnt) + 1);
		puc = (BYTE *) (pflo + 1);
		if (ui_lenFileNmPgpRtf == pflo->FileNameLength && strnicmp( puc, 
											mpc_fileNmPgpRtf, 
											ui_lenFileNmPgpRtf) == ei_SAME)	{
			//if the caller wants to be told this information...
			if (ps_hasRtfObj)	{
				//make a note of it
				f_hasRtfObj = TRUE;

				//if the caller doesn't need to be told whether a regular 
				//	PGP-encoded attachment is present or if it's already known 
				//	that one is present, we need go no further, so break out of 
				//	the loop
				if (!ps_hasPgpAtchmt || f_hasPgpAtchmt)	{
					OSUnlockBlock( bid_ctnt);
					break;
				}
			} //if (ps_hasRtfObj)
		//else if the caller wants to know whether a regular PGP-encoded 
		//	attachment is present and this is still not known and the 
		//	associated object name sports one of the PGP extensions...
		}else if (ps_hasPgpAtchmt && !f_hasPgpAtchmt)	{
			puc += pflo->FileNameLength;
			if (strnicmp( puc - mui_LEN_ARMOR_EXT_ASC, mpc_PGP_ARMOR_EXT_ASC, 
										mui_LEN_ARMOR_EXT_ASC) == ei_SAME || 
										strnicmp( puc - mui_LEN_ARMOR_EXT_PGP, 
										mpc_PGP_ARMOR_EXT_PGP, 
										mui_LEN_ARMOR_EXT_PGP) == ei_SAME)	{
				//make a note that such an attachment is present
				f_hasPgpAtchmt = TRUE;

				//if the caller doesn't need to be told whether the special 
				//	rich-text object is present or if it's already known that 
				//	it is present, we need go no further, so break out of the 
				//	loop
				if (!ps_hasRtfObj || f_hasRtfObj)	{
					OSUnlockBlock( bid_ctnt);
					break;
				}
			} //if (strnicmp( puc - mui_LEN_ARMOR_EXT_ASC,
		} //if (ui_lenFileNmPgpRtf == pflo->FileNameLength && strnicmp(

		//get a handle on the next attachment item in the note
		OSUnlockBlock( bid_ctnt);
		bid_prvItm = bid_itm;
		if ((us_err = NSFItemInfoNext( h_NOTE, bid_prvItm, 
											epc_ITEMNM_STANDARD_ATTACH, 

⌨️ 快捷键说明

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