📄 chapter_2_2.c
字号:
#include "emailkit.h"
void AnalyzeEntity( IMimeEntity_p* itfME );
int main( int argc, char* argv[] )
{
MimeMessage_p* pMM; /* MimeMessage */
AddressList_p* pFRM; /* AddressList */
AddressList_p* pTO; /* AddressList */
MimeText_p* pSJT; /* MimeText */
IAddress_p* pIA; /* IAddress */
MailAddress_p* pMA; /* MailAddress */
AddressGroup_p* pAG; /* AddressGroup */
TextEncoder_p* pTE; /* TextEncoder */
CUTF16Text_p* utVal;
int num = 0;
int num2 = 0;
int ii;
int jj;
int ret;
pMM = new_MimeMessage();
pTE = new_TextEncoder();
utVal = new_CUTF16Text();
/* 儊僢僙乕僕偺峔憿偺夝愅 */
TextEncoder_CharsetDecode( pTE, argv[1], strlen( argv[1] ), "", true, utVal );
MimeMessage_DecodeFile( pMM, CUTF16Text_GetText( utVal ) );
MimeMessage_ExtractUUParts( pMM, &ret );
/* -- From:偺庢摼 ----------------- */
/* From: 偺奿擺愭傪扵偡 */
MimeMessage_get_From( pMM, &pFRM );
/* 梫慺悢傪庢摼 */
AddressList_get_Count( pFRM, &num );
printf( "-- From: -------------\n" );
for( ii = 0; ii < num; ii++ )
{
/* 梫慺傪庢傝弌偡 */
AddressList_Item( pFRM, ii, &pIA );
/* 嶲徠愭偺敾掕 */
IAddress_IsMailAddress( pIA, &ret );
if( ret == true )
{ /* MailAddress */
pMA = ( MailAddress_p* )pIA;
/* From丗偺庢摼 */
MailAddress_get_Value( pMA, utVal );
wprintf( L"%s\n", CUTF16Text_GetText( utVal ));
}
else
{ /* AddressGroup */
pAG = ( AddressGroup_p* )pIA;
/* 梫慺悢傪庢摼 */
AddressGroup_get_Count( pAG, &num2 );
for( jj = 0; jj < num2; jj++ )
{
/* 梫慺傪庢傝弌偡 */
AddressGroup_Item( pAG, jj, &pMA );
/* From丗偺庢摼 */
MailAddress_get_Value( pMA, utVal );
wprintf( L"%s\n", CUTF16Text_GetText( utVal ));
}
}
}
/* -- To:偺庢摼 ----------------- */
/* To: 偺奿擺愭傪扵偡 */
MimeMessage_get_To( pMM, &pTO );
/* 梫慺悢傪庢摼 */
AddressList_get_Count( pTO, &num );
printf( "\n-- To: ---------------\n" );
for( ii = 0; ii < num; ii++ )
{
/* 梫慺傪庢傝弌偡 */
AddressList_Item( pTO, ii, &pIA );
/* 嶲徠愭偺敾掕 */
IAddress_IsMailAddress( pIA, &ret );
if( ret == true )
{ /* MailAddress */
pMA = ( MailAddress_p* )pIA;
/* To丗偺庢摼 */
MailAddress_get_Value( pMA, utVal );
wprintf( L"%s\n", CUTF16Text_GetText( utVal ));
}
else
{ /* AddressGroup */
pAG = ( AddressGroup_p* )pIA;
/* 梫慺悢傪庢摼 */
AddressGroup_get_Count( pAG, &num2 );
for( jj = 0; jj < num; jj++ )
{
/* 梫慺傪庢傝弌偡 */
AddressGroup_Item( pAG, jj, &pMA );
/* To丗偺庢摼 */
MailAddress_get_Value( pMA, utVal );
wprintf( L"%s\n", CUTF16Text_GetText( utVal ));
}
}
}
/* -- Subject:偺庢摼 ----------------- */
/* Subject丗偺奿擺愭傪扵偡 */
MimeMessage_get_Subject( pMM, &pSJT );
/* Subject丗偺庢摼 */
MimeText_get_Value( pSJT, utVal );
printf( "\n-- Subject: ----------\n" );
wprintf( L"%s\n\n", CUTF16Text_GetText( utVal ));
AnalyzeEntity( ( IMimeEntity_p* )pMM );
delete_MimeMessage( pMM );
delete_TextEncoder( pTE );
delete_CUTF16Text( utVal );
Sleep(10*1000);
return 0;
}
void AnalyzeEntity( IMimeEntity_p* itfME )
{
MimeBodyPart_p* pMB; /* MimeBodyPart */
MultipartBody_p* pMPB; /* MultipartBody */
ContentDisposition_p* pCD; /* ContentDisposition */
ContentType_p* pCT; /* ContentType */
FieldParameters_p* pFPS; /* FieldParameters */
FieldParameter_p* pFP; /* FieldParameter */
CUTF16Text_p* utVal;
CMultiByteText_p* mtVal;
int idx;
int ii;
int num;
int ret;
utVal = new_CUTF16Text();
mtVal = new_CMultiByteText();
/* -- 杮暥偲揧晅僼傽僀儖柤偺嶲徠 ----------------- */
IMimeEntity_IsMultipart( itfME, &ret );
if( ret == true )
{ /* 儅儖僠僷乕僩 */
IMimeEntity_get_MultipartBody( itfME, &pMPB );
/* MimeBodyPart偺屄悢傪庢摼 */
MultipartBody_get_Count( pMPB, &num );
for( ii = 0; ii < num ; ii++ )
{
/* 梫慺傪庢摼 */
MultipartBody_Item( pMPB, ii, &pMB );
AnalyzeEntity( ( IMimeEntity_p* )pMB );
}
}
else
{ /* 旕儅儖僠僷乕僩 */
IMimeEntity_IsPlainText( itfME, &ret );
IMimeEntity_get_ContentDisposition( itfME, &pCD );
ContentDisposition_get_Value( pCD, mtVal );
/* text/plain偱丄Content-Disposition偑側偄偐"inline" */
if( ( ret == true ) &&
( ( strcmp( CMultiByteText_GetText( mtVal ), "" ) == 0 ) ||
( strcmp( CMultiByteText_GetText( mtVal ), "inline" ) == 0 ) ) )
{
/* 杮暥偺庢摼 */
IMimeEntity_GetText( itfME, utVal );
/* 儊僢僙乕僕偺峔憿偺夝愅 */
printf( "-- Text: -------------\n" );
wprintf( L"%s\n\n", CUTF16Text_GetText( utVal ));
}
else
{
IMimeEntity_get_ContentType( itfME, &pCT );
ContentType_get_Value( pCT, mtVal );
if( strcmp( CMultiByteText_GetText( mtVal ), "application/applefile" ) != 0 )
{ /* 堎側傞応崌 */
/* Content-Disposition丗偺filename傪専嶕 */
IMimeEntity_get_ContentDisposition( itfME, &pCD );
ContentDisposition_get_Parameters( pCD, &pFPS );
FieldParameters_Find( pFPS, "filename", 0, true, &idx );
if( idx >= 0 )
{
FieldParameters_Item( pFPS, idx, &pFP );
/* filename庢摼 */
FieldParameter_get_Value( pFP, utVal );
}
else
{
/* Content-Type:偺name=傪専嶕 */
ContentType_get_Parameters( pCT, &pFPS );
FieldParameters_Find( pFPS, "name", 0, true, &idx );
if( idx >= 0 )
{
FieldParameters_Item( pFPS, idx, &pFP );
/* name庢摼 */
FieldParameter_get_Value( pFP, utVal );
}
}
}
printf( "-- Attachment: -------\n" );
wprintf( L"%s\n\n", CUTF16Text_GetText( utVal ));
}
}
delete_CUTF16Text( utVal );
delete_CMultiByteText( mtVal );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -