Beispiel #1
0
BOOL CMime::SaveBase64(LPMIMEBLOCK pmb, LPCTSTR pFile)
{_STT();
	// Open file
	CWinFile f;
	if ( !f.OpenNew( pFile ) ) return FALSE;

	DWORD	i = 0;
	BYTE	buf[ 1024 ];
	DWORD	size = sizeof( buf ), decoded;
	DWORD	done = 0;

	// Decode to file
	while( !done && i < pmb->dsize )
	{
		DWORD block = 1024 < ( pmb->dsize - i ) ? 1024 : pmb->dsize - i;

		if ( !CBase64::Decode( &( (LPCTSTR)pmb->pdata )[ i ], &block, buf, &decoded, &done ) )
			done = TRUE;

		// Write data to file
		if ( decoded ) f.Write( buf, decoded );

		// Increment buffer pointer
		i += block;

	} // end while

	// Close the file
	f.Close();

	return TRUE;
}
Beispiel #2
0
BOOL CMime::Load(LPCTSTR pFile)
{_STT();
	// Out with the old
	Destroy();

	CWinFile	file;

	// Open the file
	if ( !file.OpenExisting( pFile, GENERIC_READ ) )
		return FALSE;

	// Get file size
	DWORD size = file.Size();
	if ( size == 0 ) return FALSE;

	// Allocate memory
	TMem< BYTE > buf;
	if ( !buf.allocate( size + 1 ) ) return FALSE;

	// Read in the data into ram
	DWORD read;
	if ( !file.Read( buf, size, &read ) || read != size )
		return FALSE;
	buf[ size ] = 0;

	// Load the file
	if ( !LoadFromMemory( buf, size ) )
		return FALSE;

	return TRUE;
}
Beispiel #3
0
BOOL CReg::LoadRegFile(LPCTSTR pFile, LPCTSTR pKey, BOOL bMerge )
{_STTEX();
	if ( pFile == NULL ) return FALSE;

	// Lose old record
	if ( !bMerge ) Destroy();

	CWinFile	file;

	// Open the file
	if ( !file.OpenExisting( pFile, GENERIC_READ ) )
		return FALSE;

	// Set crypto key if needed
	if ( pKey != NULL ) file.CryptoSetKey( pKey );

	// Get file size
	DWORD size = file.Size();
	if ( size == 0 ) return FALSE;

	// Allocate memory
	LPBYTE buf = new BYTE[ size + 2 ];
	if ( buf == NULL ) return FALSE;

	// Read in the data into ram
	DWORD read;
	if ( !file.Read( buf, size, &read ) || read != size )
	{	delete[] buf; return FALSE; }
	buf[ size ] = 0;
	buf[ size + 1 ] = 0;

	// Check for wide character file
	if ( *( (unsigned short*)buf ) == 0xfffe || *( (unsigned short*)buf ) == 0xfeff )
	{
		LPBYTE b2 = new BYTE[ size + 1 ];
		if ( b2 == NULL ) { delete [] buf; return FALSE; }

		// Convert wide characters
		size = wcstombs( (char*)b2, (wchar_t*)&buf[ 2 ], size );

		// Did it work ?
		if ( size == 0 || size == MAXDWORD ) 
		{	delete [] buf; delete [] b2; return FALSE; }
		b2[ size ] = 0;	

		// Switch to multi-byte buffer
		delete [] buf;
		buf = b2;

	} // end if

	// Load the file
	if ( !LoadRegFromMem( buf, size, bMerge ) )
	{	delete[] buf; return FALSE; }

	delete[] buf;

	return TRUE;
}
Beispiel #4
0
BOOL CEmailThread::Email(	LPCTSTR pImg, LPCTSTR pDiskFile,
							LPCTSTR pTo, LPCTSTR pFrom, 
							LPCTSTR pSubject, LPCTSTR pFile, 
							LPCTSTR pServer, LPCTSTR pUsername, 
							LPCTSTR pPassword, LPCTSTR pBody, 
							DWORD dwLogin, DWORD dwAuthDetect, 
							DWORD dwAuthType)
{
	// Are we already e-mailing?
	if ( 	WaitForSingleObject( m_hEmail, 0 ) != WAIT_TIMEOUT ||
			m_smtp.IsConnecting() || m_smtp.IsConnected() ) return FALSE;

	// Copy message data
	m_to.copy( pTo );
	m_from.copy( pFrom );
	m_subject.copy( pSubject );
	m_fname.copy( pFile );
	m_body.copy( pBody );

	// Copy server data
	m_server.copy( pServer );
	m_username.copy( pUsername );
	m_password.copy( pPassword );

	m_login = dwLogin;
	m_authdetect = dwAuthDetect;
	m_authtype = dwAuthType;
	
	m_sImg.copy( pImg );

	// Load disk file if needed
	m_mem.destroy();
	if ( pDiskFile != NULL )
	{	CWinFile wf;
		if ( wf.OpenExisting( pDiskFile ) )
		{	DWORD size = wf.Size();
			if ( size && m_mem.allocate( size ) )
				wf.Read( m_mem.ptr(), size );
		} // end if
	} // end if

	// Validate params
	if ( m_server.size() == 0 || m_from.size() == 0 ) return FALSE;

	StartThread();

	// Signal send email
	Email();

	return TRUE;
}
Beispiel #5
0
template<typename T> static bool LoadFileData( const std::string& filepath, T& data )
{
	CWinFile ifile;
	if( ifile.Open( filepath, OPEN_EXISTING ) )
	{
		data.resize( ifile.GetFileSize() );
		if( data.size() )
		{
			ifile.Read( &data[0], data.size() );
			return true;
		}
	}
	return false;
}
Beispiel #6
0
BOOL CCfgFile::Load(LPCTSTR pFile, BOOL bMerge)
{_STTEX();
	if ( pFile == NULL ) return FALSE;

	// Lose old record
	if ( !bMerge ) Destroy();
	if ( !bMerge ) strcpy( m_szFileName, pFile );

	CWinFile	file;

	// Set crypto key
	if ( *m_szKey ) file.CryptoSetKey( m_szKey );

	// Open the file
	if ( !file.OpenExisting( pFile, GENERIC_READ ) )
		return FALSE;

	// Get file size
	DWORD size = file.Size();
	if ( size == 0 ) return FALSE;

	// Allocate memory
	TMem< BYTE > buf;
	if ( !buf.allocate( size + 1 ) ) return FALSE;

	// Read in the data into ram
	DWORD read;
	if ( !file.Read( buf, size, &read ) || read != size )
		return FALSE;
	buf[ size ] = 0;

	// Load the file
	if ( !LoadFromMem( buf, size, bMerge ) )
		return FALSE;

	if ( !bMerge ) strcpy( m_szFileName, pFile );

	return TRUE;
}
Beispiel #7
0
BOOL CMime::Save(LPCTSTR pFile)
{_STT();
	CWinFile f;

	// Attempt to open the new file
	if ( !f.OpenNew( pFile ) ) return FALSE;

	// How much data
	DWORD size = SaveToMem( NULL, 0 );
	if ( size == 0 ) return TRUE;

	// Allocate memory
	TMem< BYTE > buf;
	if ( !buf.allocate( size + 1 ) ) return FALSE;

	// Write MIME to buffer
	DWORD bytes = SaveToMem( buf, size );

	// Write out the data to disk file
	f.Write( buf, bytes );

	return TRUE;
}
Beispiel #8
0
BOOL CMime::SaveToFile(LPMIMEBLOCK pmb, LPCTSTR pFile)
{_STT();
	// Sanity check
	if ( pmb == NULL || pFile == NULL ) return FALSE;
	if ( pmb->pdata == NULL || pmb->dsize == 0 ) return FALSE;

	if( ( pmb->f1 & MBF1_DECODED ) == 0 )
	{
		// If encoding
		if ( ( pmb->encode & MBEN_BASE64 ) != 0 )
			return SaveBase64( pmb, pFile );
	} // end if

	// Open file
	CWinFile f;
	if ( !f.OpenNew( pFile ) ) return FALSE;

	// Just write out if no encoding
	f.Write( pmb->pdata, pmb->dsize );
	f.Close();

	return TRUE;
}
Beispiel #9
0
BOOL CPubThread::Ftp( LPPUBINFO ppi )
{
	if ( ppi == NULL ) return FALSE;

	// Ensure ftp server
	HGROUP hGroup = FTPSERVERS().FindGroup( ppi->str );
	if ( hGroup == NULL )
	{	_Log( MB_ICONERROR, ppi->str, "FTP Server information not found" );	
		return FALSE;
	} // end if

	BOOL bPublished = FALSE;
	LPBYTE buf = NULL;
	DWORD size = 0;
	TMem< BYTE > temp;
	CWinImg img;

	// Is it an avi file
	if ( *ppi->avicachefile != 0 )
	{
		CWinFile wf;
		if ( wf.OpenExisting( ppi->avicachefile ) )
		{	size = wf.Size();
			if ( size && temp.allocate( size ) && wf.Read( temp.ptr(), temp.size() ) )
				buf = (LPBYTE)temp.ptr();
		} // end if
		
	} // end if
	else
	{
		// Get the image
		if ( !IMGLIST().GetImage( ppi->img, &img ) )
		{	_Log( MB_ICONERROR, ppi->img, "Image not found" );	
			return FALSE;
		} // end if

		// Set jpeg quality
		FRAME()->SetQuality( &img );

		// Encode the file
		if ( !img.Encode( &buf, &size, ppi->pub_fname ) ) 
		{	_Log( MB_ICONERROR, ppi->img, img.GetLastError() );	
			return FALSE;
		} // end if

	} // end else

	// Want Win32 interface?
	if ( FTPSERVERS().GetDword( hGroup, "Rename", FALSE ) )
	{
		// Create FTP object if needed
		if ( ppi->pftp == NULL ) ppi->pftp = new CFtp();
		if ( ppi->pftp == NULL )
		{	_Log( MB_ICONERROR, "Ftp()", "Out of memory" );	
			return FALSE;
		} // end if

		// Is the FTP already working?
		if ( !ppi->pftp->IsConnecting() && !ppi->pftp->IsConnected() )
		{

			// Copy the memory
			if ( ppi->mem == NULL || !ppi->mem->put( buf, size ) )
			{	_Log( MB_ICONERROR, "Ftp()", "Memory error" );	
				return FALSE;
			} // end if

			// Upload the data
			bPublished = FtpImage( ppi->str, ppi->pftp, *ppi->mem, ppi->mem->size(), ppi->pub_fname );
		} // end if

	} // end if

	else 
	{
		// Create FTP object if needed
		if ( ppi->pw32ftp == NULL ) ppi->pw32ftp = new CNetFile();
		if ( ppi->pw32ftp == NULL )
		{	_Log( MB_ICONERROR, "Ftp()", "Out of memory" );	
			return FALSE;
		} // end if

		// Use Windows interface
		bPublished = FtpImage( ppi->str, ppi->pw32ftp, buf, size, ppi->pub_fname );

	} // end else

	// Punt if no thumbnail
	if ( ( ppi->f1 & PUBF1_THUMBNAIL ) == 0 ) return bPublished;

	// Load image if we haven't already
	if ( !img.IsValid() )
	{
		// Get the image
		if ( !IMGLIST().GetImage( ppi->img, &img ) )
		{	_Log( MB_ICONERROR, ppi->img, "Image not found" );	
			return FALSE;
		} // end if

		// Set jpeg quality
		FRAME()->SetQuality( &img );

		// Encode the file
		if ( !img.Encode( &buf, &size, ppi->pub_fname ) ) 
		{	_Log( MB_ICONERROR, ppi->img, img.GetLastError() );	
			return FALSE;
		} // end if

	} // end if

	// Get the thumbnail image
	if ( !GetThumbnail( ppi, &img, img.GetWidth(), img.GetHeight() ) )
		return FALSE;

	// Set jpeg quality
	FRAME()->SetQuality( &img );

	// Encode the thumbnail file
	if ( !img.Encode( &buf, &size, ppi->pub_tfname ) ) return FALSE;

	// Want Win32 interface?
	if ( FTPSERVERS().GetDword( hGroup, "Rename", FALSE ) )
	{
		// Create FTP object if needed
		if ( ppi->pftpthm == NULL ) ppi->pftpthm = new CFtp();
		if ( ppi->pftpthm == NULL )
		{	_Log( MB_ICONERROR, "Ftp()", "Out of memory" );	
			return FALSE;
		} // end if

		// Is the FTP already working?
		if ( !ppi->pftpthm->IsConnecting() && !ppi->pftpthm->IsConnected() )
		{
			// Copy the memory
			if ( ppi->tnmem == NULL || !ppi->tnmem->put( buf, size ) )
			{	_Log( MB_ICONERROR, "Ftp()", "Memory error" );
				return FALSE;
			} // end if

			// Upload the data
			FtpImage( ppi->str, ppi->pftpthm, *ppi->tnmem, ppi->tnmem->size(), ppi->pub_tfname );

		} // end if

	} // end if

	else 
	{
		// Create FTP object if needed
		if ( ppi->pw32ftpthm == NULL ) ppi->pw32ftp = new CNetFile();
		if ( ppi->pw32ftpthm == NULL )
		{	_Log( MB_ICONERROR, "Ftp()", "Memory error" );
			return FALSE;
		} // end if

		// Use Windows interface
		FtpImage( ppi->str, ppi->pw32ftpthm, buf, size, ppi->pub_tfname );

	} // end else

	return bPublished;
}
Beispiel #10
0
LPREGVALUE CRKey::Add( DWORD dwType, LPCTSTR pName, const void * pValue, DWORD dwValue, BOOL bFile)
{_STTEX();
	BOOL bNew = FALSE;
	LPREGVALUE prv = (LPREGVALUE)Find( pName );

	// Did we find an existing object?
	if ( prv != NULL ) 
		ResetObject( prv, NULL, 0, (LPVOID)pName ); 

	else // Create new object
	{	prv = (LPREGVALUE)New( NULL, 0, (LPVOID)pName );
		if ( prv == NULL ) return NULL;
	} // end else

	// Save the type
	prv->type = dwType;

	RULIB_TRY
	{
		if ( bFile )
		{
			CWinFile wf;
			if ( wf.OpenExisting( (char*)pValue ) )
			{
				DWORD dwSize = wf.Size();
				if ( dwSize < m_dwMinSize ) dwSize = m_dwMinSize;
				if ( dwSize )
				{
					// Allocate memory
					prv->data = new BYTE[ dwSize + 1 ];
					if ( prv->data == NULL ) 
					{	Delete( prv ); return FALSE; }
					prv->size = dwSize;

					// Read data from file
					if ( !wf.Size() || !wf.Read( prv->data, wf.Size() ) )
						ZeroMemory( prv->data, prv->size );

				} // end if

			} // end if

			else bFile = FALSE;

		} // end if

		// Save the data
		if ( !bFile && ( dwValue != 0 || m_dwMinSize != 0 ) )
		{
			// What size should we use
			DWORD sz = m_dwMinSize < dwValue ? dwValue : m_dwMinSize;

			// Allocate memory
			prv->data = new BYTE[ sz + 1 ];
			if ( prv->data == NULL ) 
			{	Delete( prv ); return FALSE; }
			prv->size = sz;

			// Initialize data
			if ( pValue != NULL && dwValue != 0 ) 
			{	memcpy( prv->data, pValue, dwValue );
				( (LPBYTE)prv->data )[ dwValue ] = 0;
			} // end if
			else ZeroMemory( prv->data, sz + 1 );

		} // end if	

	} // end try

	// Just forget it if error
	RULIB_CATCH_ALL { ASSERT( 0 ); return NULL; }

	return prv;
}
Beispiel #11
0
BOOL CCfgFile::Save(LPCTSTR pFile)
{_STTEX();
	CWinFile	file;

	// Set crypto key
	if ( *m_szKey ) file.CryptoSetKey( m_szKey );

	// Verify file name
	if ( pFile == NULL ) pFile = m_szFileName;

	// Open the file
	if ( !file.OpenNew( pFile, GENERIC_WRITE ) ) return FALSE;

	// Write out header
	file.Write( "; Configuration File\r\n;\r\n" );

	LPCFGGROUPINFO	pcgi = NULL;
	while ( ( pcgi = GetNext( pcgi ) ) != NULL )
	{
		// Write out the name
		if ( *pcgi->name != NULL )
		{	file.Write( "\r\n;-----------------------------------------------------------------" );
			file.Write( "\r\n[" );
			file.Write( pcgi->name );
			file.Write( "]" );
			file.Write( "\r\n;-----------------------------------------------------------------" );
			file.Write( "\r\n;\r\n" );
		} // end if

		// Write out file data
		TMem< char >		buf;
		DWORD				size;
		char				msg[ CFG_STRSIZE ];
		LPCFGELEMENTINFO	pcei = NULL;
		while ( ( pcei = GetNextElement( pcgi, pcei ) ) != NULL )
		{
			if ( !strcmpi( pcei->name, "font" ) )
			{	int x = 0; }

			// Write out type
			if ( pcei->type != 0 )
			{
				wsprintf( msg, "%lu:", pcei->type );
				if ( !file.Write( msg ) ) return FALSE;
			} // end if

			// Write out the name
			size = GetMinCanonicalizeBufferSize( strlen( pcei->name ) );
			if ( buf.allocate( size + 1 ) )
			{
				// Write string
				if ( CanonicalizeBuffer( buf, (LPBYTE)pcei->name, strlen( pcei->name ) ) )
					file.Write( buf, strlen( buf ) );

				buf.destroy();
			} // end if

			if ( pcei->size != 0 || pcei->value != NULL || pcei->type != 0 )
			{
				// Write out the equator
				if ( pcei->type == CFG_DWORD ) 
					file.Write( "=#" );
				else file.Write( "=>" );

				// Write out DWORD value
				if ( pcei->type == CFG_DWORD )
				{
					wsprintf( msg, "%lu:", pcei->value );
					if ( !file.Write( msg ) ) return FALSE;
				} // end if

				else if ( size > 0 )
				{
					// Write out the data
					size = GetMinCanonicalizeBufferSize( pcei->size );
					if ( buf.allocate( size + 1 ) )
					{
							// Write string
						if ( CanonicalizeBuffer( buf, (LPBYTE)pcei->value, pcei->size ) )
							file.Write( buf, strlen( buf ) );

						buf.destroy();
					} // end if

				} // end else

			} // end if

			file.Write( "\r\n" );
					
		} // end while

	} // end while

	return TRUE;
}
Beispiel #12
0
DWORD CCfgFile::SaveToMem(LPBYTE ptr, DWORD len)
{_STTEX();
	DWORD		i = 0;
	CWinFile	file;

	// Set crypto key
	if ( *m_szKey ) file.CryptoSetKey( m_szKey );

	// Write out header
	WRITESZ( "; Configuration File\r\n;\r\n" );

	LPCFGGROUPINFO	pcgi = NULL;
	while ( ( pcgi = GetNext( pcgi ) ) != NULL )
	{
		// Write out the name
		if ( *pcgi->name != NULL )
		{	WRITESZ( "\r\n;-----------------------------------------------------------------" );
			WRITESZ( "\r\n[" );
			WRITESZ( pcgi->name );
			WRITESZ( "]" );
			WRITESZ( "\r\n;-----------------------------------------------------------------" );
			WRITESZ( "\r\n;\r\n" );
		} // end if

		// Write out file data
		TMem< char >		buf;
		DWORD				size;
		char				msg[ CFG_STRSIZE ];
		LPCFGELEMENTINFO	pcei = NULL;
		while ( ( pcei = GetNextElement( pcgi, pcei ) ) != NULL )
		{
			// Write out type
			if ( pcei->type != 0 )
			{
				wsprintf( msg, "%lu:", pcei->type );
				WRITESZ( msg );
			} // end if

			// Write out the name
			size = GetMinCanonicalizeBufferSize( strlen( pcei->name ) );
			if ( buf.allocate( size + 1 ) )
			{
				// Write string
				if ( CanonicalizeBuffer( buf, (LPBYTE)pcei->name, strlen( pcei->name ) ) )
					WRITE( buf, strlen( buf ) );

				buf.destroy();

			} // end if

			if ( pcei->size != 0 || pcei->value != NULL || pcei->type != 0 )
			{
				// Write out the equator
				if ( pcei->type == CFG_DWORD ) 
					WRITESZ( "=#" );
				else WRITESZ( "=>" );

				// Write out DWORD value
				if ( pcei->type == CFG_DWORD )
				{
					wsprintf( msg, "%lu:", pcei->value );
					WRITESZ( msg );
				} // end if

				else if ( size > 0 )
				{
					// Write out the data
					size = GetMinCanonicalizeBufferSize( pcei->size );
					if ( buf.allocate( size + 1 ) )
					{
							// Write string
						if ( CanonicalizeBuffer( buf, (LPBYTE)pcei->value, pcei->size ) )
							WRITE( buf, strlen( buf ) );

						buf.destroy();
					} // end if

				} // end else

			} // end if

			WRITESZ( "\r\n" );
					
		} // end while

	} // end while

	return i;
}
Beispiel #13
0
BOOL CNetFile::Download(LPCTSTR pUrl, LPCTSTR pLocal, BOOL bCloseFileAfterDownload, HWND hWndParent)
{_STT();
	// Lose previous file
	Destroy();

	// Downloading
	m_bUpload = FALSE;

	// Save parent window
	m_hWndParent = hWndParent;

	// Save close file status
	m_bCloseFileAfterDownload = bCloseFileAfterDownload;

	// Sanity check
	if ( pUrl == NULL || *pUrl == NULL ) return FALSE;

	// Are we downloading to file or ram?
	m_bMem = ( pLocal == NULL );

	{ // Copy the url
		
		char buf[ sizeof( m_szUrl ) ];
		DWORD size = sizeof( m_szUrl ) - 1;

		// Is it a local file?
		if ( GetFileAttributes( pUrl ) == MAXDWORD )
		{
			// Fix the url
			if ( InternetCanonicalizeUrl( pUrl, buf, &size, 0 ) )
			{	strcpy_sz( m_szUrl, buf ); }

			// Copy the url name
			else strcpy_sz( m_szUrl, pUrl );
		} // end if
		
		// Copy the local file name
		else strcpy_sz( m_szUrl, pUrl );

	} // end copy url	

	// Is it a local file?
	if ( GetFileAttributes( m_szUrl ) != MAXDWORD )
	{
		CWinFile	file;

		if ( file.OpenExisting( m_szUrl, GENERIC_READ ) )
		{
			DWORD size = file.Size();

			if ( m_bMem )
			{
				// Allocate memory
				m_pMem = new BYTE[ size + 1 ];
				if ( m_pMem == NULL ) 
				{	m_dwTransferStatus = NETFILE_DS_ERROR;
					return FALSE;
				} // end if

				// Read in the file
				if ( !file.Read( m_pMem, size, &m_dwDataRead ) )
				{	m_dwTransferStatus = NETFILE_DS_ERROR;
					return FALSE;
				} // end if

				// NULL terminate for good measure
				m_pMem[ size ] = 0;

			} // end if

			else
			{
				// Where to download the file
				if ( pLocal != DOWNLOADTEMP ) { strcpy_sz( m_szLocal, pLocal ); }
				else CWinFile::CreateTemp( m_szLocal );	

				// Copy the file
				CopyFile( m_szUrl, m_szLocal, FALSE );

				// Open the file
				if ( !m_local.OpenExisting( m_szLocal, GENERIC_READ | GENERIC_WRITE ) )
				{	m_dwTransferStatus = NETFILE_DS_ERROR;
					return FALSE;
				} // end if

				// Get the file size
				m_dwDataRead = m_local.Size();

			} // end else

			// Memory read complete
			m_dwTransferStatus = NETFILE_DS_DONE;

			return TRUE;

		} // end if

	} // end if

	if ( !m_bMem )
	{
		// Where to download the file
		if ( pLocal != DOWNLOADTEMP ) { strcpy_sz( m_szLocal, pLocal ); }
		else CWinFile::CreateTemp( m_szLocal );	

		// Create a file to load data
		if ( !m_local.OpenNew( m_szLocal, GENERIC_READ | GENERIC_WRITE ) )
			return FALSE;
	} // end else
	
	// Set status	
	m_dwTransferStatus = NETFILE_DS_INITIALIZING;

	// Create a thread to download the file
	if ( !StartThread() )
	{	Destroy();
		m_dwTransferStatus = NETFILE_DS_ERROR;		
		return FALSE;
	} // end if

	return TRUE;
}
Beispiel #14
0
LPMIMEBLOCK CMime::AddFile(LPCTSTR pFile, LPCTSTR pName, DWORD flags )
{_STT();
	// Sanity checks
	if ( pFile == NULL ) return FALSE;
	if ( !CWinFile::DoesExist( pFile ) ) return FALSE;

	// Open the file
	CWinFile f;
	if ( !f.OpenExisting( pFile, GENERIC_READ ) ) return FALSE;
	DWORD size = f.Size();

	// Allocate memory
	LPMIMEBLOCK node = new MIMEBLOCK;
	if ( node == NULL ) return NULL;
	ZeroMimeBlock( node );

	// Get the file name
	if ( pName != NULL ) { strcpy_sz( node->fname, pName ); }
	else CWinFile::GetFileNameFromPath( pFile, node->fname );

	// Get MIME type
	GetContentType( node->fname, node->ctype );

	// Create Content-Type string
	char typestr[ MIME_STRSIZE ];
	wsprintf( typestr, "%s;\r\n\tname=\"%s\"", node->ctype, node->fname );

	// Save header information
	node->var.AddVar( "Content-Type", typestr );
	node->var.AddVar( "Content-Transfer-Encoding", "base64" );

	if ( ( flags & MBF1_ATTACHMENT ) != 0 )
	{
		char disp[ MIME_STRSIZE ];
		wsprintf( disp, "attachment;\r\n\tfilename=\"%s\"", node->fname );
		node->var.AddVar( "Content-Disposition", disp );
	} // end if

	// Save flags
	node->f1 = flags;
	node->f1 |= MBF1_DECODED;

	// Use base64 encoding
	node->encode = MBEN_BASE64;

	if ( size > 0 )
	{
		// Allocate memory
		node->pdata = new char[ size + 1 ];
		if ( node->pdata == NULL ) { delete node; return FALSE; }

		// Read in file data
		if ( !f.Read( node->pdata, size, &node->dsize ) )
		{	delete [] node->pdata; delete node; return FALSE; }

		// NULL terminate (just in case)
		( (LPBYTE)node->pdata )[ size ] = 0;

	} // end if

	return AddBlock( node );
}