Exemple #1
0
DWORD CLotusNote::ExtractFile(BLOCKID item_blockid, char *file_path, ENCRYPTION_KEY *key)
{
	if (m_hnote == NULL) return Error_Handle("ExtractFile ... failed");
	return CLotusSection::Add_NApi_code_msg(NSFNoteExtractFile(m_hnote,item_blockid,file_path,key),SSIZE(m_err_msg),"CLotusNote::ExtractFile->NSFNoteExtractFile");
}
Exemple #2
0
/** eus_appendAtchPartToFile( ***
Appends the contents of a body-with-attachment Notes MIME-part to a file opened 
and prepared to be written to. The content of the Notes MIME-part item is 
expanded to include the attachment, and the attachment is base64 encoded if 
necessary.

--- parameters & return ----
pv_file: Input & Output. Address of opaque file object for use with 
	LibFileSystem module. Object will be updated as a part of the call. 
	Procedure assumes file is writable.
pt_CTNT: address of information structure describing the source Notes MIME-part 
	information
BID: BlockID associated with the item describing the attachment on the note
h_NOTE: handle to the note containing the attachment
pui_len: Output. Address of variable to receive the length of the resulting 
	body content, including the length of any headers.
RETURN:
	eus_ERR_INVLD_ARG if any input is obviously invalid
	!eus_SUCCESS if a temporary file couldn't be created or base64 encoded
	eus_SUCCESS if no error occured
	the Notes API error code otherwise

--- revision history -------
3/14/03 PR: created			*/
STATUS eus_appendAtchPartToFile( void *const  pv_file, 
									const MimePrtItmCtnt *const  pt_CTNT, 
									const BLOCKID  BID, 
									const NOTEHANDLE  h_NOTE, 
									DWORD *const  pui_len)	{
	char * pc_extFileNmDtch, * pc_extFileNmDecd;
	size_t  ui_, ui;
	BYTE * puc;
	FILE * pv_fl = NULL;
	STATUS  us_err;
	BOOL  f_fail;

	if (!( pv_file && pt_CTNT && BID.pool && h_NOTE && pui_len))
		return eus_ERR_INVLD_ARG;

	*pui_len = NULL;

	//detach the in-line attachment to a temporary file
//suggested enhancment: could read the contents directly out of the attachment 
//	object if object is not compressed (and do the base64 encoding all in 
//	memory, as necessary)
	if (!(pc_extFileNmDtch = _tempnam( NULL, epc_TILDE)))
		return !eus_SUCCESS;
	if (us_err = NSFNoteExtractFile( (NOTEHANDLE) h_NOTE, BID, 
												pc_extFileNmDtch, NULL))	{
		free( pc_extFileNmDtch);
		return us_err;
	}

	//append all of the part's contents except its body
	ui_ = pt_CTNT->puc_bdy - pt_CTNT->puc_ctnt;
	if (f_fail = el_addToOpenFile( pv_file, pt_CTNT->puc_ctnt, ui_, FALSE) == 
																		ei_FAIL)
		goto errJump;

	//if a transfer-encoding header is present...
	if (puc = epc_strInBuf( epc_MIMHDR_CTNT_ENC, pt_CTNT->puc_typ, 
										pt_CTNT->puc_bdy - pt_CTNT->puc_typ, 
										eus_LEN_MIMHDR_CTNT_ENC))	{
		//if the encoding is base64...
		if (strnicmp( puc + eus_LEN_MIMHDR_CTNT_ENC, epc_MIM_CTNTENC_B64, 
										eus_LEN_MIM_CTNTENC_B64) == ei_SAME)	{
			//base64 encode the associated file and keep it opened
			if (f_fail = !(pc_extFileNmDecd = _tempnam( NULL, epc_TILDE)))
				goto errJump;
			if (f_fail = !ef_base64encodeFile( pc_extFileNmDtch, 
												pc_extFileNmDecd, &pv_fl))	{
				free( pc_extFileNmDecd);
				goto errJump;
			}

			//append the base64-encoded file's contents to the file being 
			//	prepared for PGP-decoding, then get rid of the base64-encoded 
			//	file
			if (f_fail = ((int) ui = (UINT) ei_appendFileContent( pv_file, 
															pv_fl, NULL, NULL, 
															NULL)) == ei_FAIL)
				goto errJump;
			if (f_fail = !ef_closeAndDeleteFile( pv_fl, pc_extFileNmDecd))
				goto errJump;
			free( pc_extFileNmDecd);
			pv_fl = NULL;
		//else we don't handle that encoding type yet, so set up failure
		}else
			us_err = eus_ERR_INVLD_ARG;
	//else assume the attachment is to be streamed in as is
	}else
		f_fail = (int) (ui = (UINT) ei_appendFileContent( pv_file, NULL, NULL, 
											pc_extFileNmDtch, NULL)) == ei_FAIL;

	//tell caller the total length of the part, including the attachment 
	//	content
	if (!( us_err + f_fail))
		*pui_len = ui + ui_;

errJump:
	if (pv_fl)	{
		if (!( ef_closeAndDeleteFile( pv_fl, pc_extFileNmDecd) || us_err + 
																		f_fail))
			f_fail = TRUE;
		free( pc_extFileNmDecd);
	}
	if (pc_extFileNmDtch)	{
		//delete the detached file, ignoring failure
		remove( pc_extFileNmDtch);
		free( pc_extFileNmDtch);
	}

	return us_err + f_fail;
} //eus_appendAtchPartToFile(