|
> 出来れば、鶴亀で送信する時に、添付ファイルの名前が日本語の場合、
> RFC2331と従来の方法のどちらかが選べるようにしていただけるとうれ
> しいです。
受信側を作るのにもかなり時間がかかったので、送信側はもっともっと後に
したいなぁと…。
参考までに、以下、ソースコード(filename*=関係をfilename=に変換する処理)
BOOL CAddBuffer::ConvertRFC2231( int x ) {
char* pch = pb + x;
char* pchEnd = pch;
do {
pchEnd = SkipOneLine( pchEnd );
} while( *pchEnd == ' ' || *pchEnd == '\t' );
char* pchNextPart = (char*)memchr( pch, ';', (int)pchEnd - (int)pch );
if( pchNextPart == NULL ) {
return FALSE;
}
CAddBuffer strNew;
char* pchParamName = NULL;
int cchParamName;
BOOL fReplaced = FALSE;
Restart:
while( *pchNextPart == ';' ) {
pch = pchNextPart;
pch ++;
pchNextPart = (char*)memchr( pch, ';', (int)pchEnd - (int)pch );
if( pchNextPart == NULL ) {
pchNextPart = pchEnd;
}
while( pch < pchEnd && *pch <= ' ' ) {
pch ++;
}
char* pchParamName2 = pch;
while( isalpha( *pch ) ) {
pch ++;
}
int cchParamName2 = (int)pch - (int)pchParamName2;
if( pchParamName != NULL ) {
if( cchParamName != cchParamName2
|| memcmp( pchParamName, pchParamName2, cchParamName ) != 0 ) {
// 置き換え
int cchDecrease = (int)pchNextPart - (int)pchParamName - str
New.GetLength();
memcpy( pchParamName, strNew.Direct(), strNew.GetLength() );
memcpy( pchParamName + strNew.GetLength(), pchNextPart, cb +
1 - ( (int)pchNextPart - (int)pb ) );
cb -= cchDecrease;
pchNextPart -= cchDecrease;
pchParamName2 -= cchDecrease;
pch -= cchDecrease;
pchEnd -= cchDecrease;
fReplaced = TRUE;
goto Label_NewParam;
}
} else {
Label_NewParam:;
if( *pch != '*' ) {
pchParamName = NULL;
continue;
}
pchParamName = pchParamName2;
cchParamName = cchParamName2;
strNew.Empty();
strNew.Add( pchParamName, cchParamName );
strNew += "=";
}
if( *pch != '*' ) {
// RFC2231形式じゃない
pchParamName = NULL;
continue;
}
// RFC2231形式の場合
BOOL fDecode;
pch ++;
if( *pch >= '0' && *pch <= '9' ) {
// filename*0=XXXXX
// filename*0*=XXXXX の形式
pch ++;
if( *pch == '*' ) {
fDecode = TRUE;
pch ++;
} else {
fDecode = FALSE;
}
} else {
// filename*=iso-2022-jp'ja' のような形式の場合かどうか
fDecode = TRUE;
}
while( *pch != '=' ) {
if( pch >= pchNextPart ) {
goto Restart;
}
pch ++;
}
pch ++;
while( *pch == ' ' || *pch == '\t' ) {
if( pch >= pchNextPart ) {
goto Restart;
}
pch ++;
}
BOOL fQuoted = FALSE;
if( *pch == '\"' ) {
pch ++;
fQuoted = TRUE;
}
if( fDecode ) {
// ' を2つスキップする
while( *pch != '\'' ) {
if( pch >= pchNextPart ) {
goto Restart;
}
pch ++;
}
pch ++;
while( *pch != '\'' ) {
if( pch >= pchNextPart ) {
goto Restart;
}
pch ++;
}
pch ++;
while( *pch >= ' ' && pch < pchNextPart && (!fQuoted || *pch !=
'\"') ) {
if( *pch == '%' ) {
char ch = (GetHexCode( pch[1] ) << 4) + GetHexCode( p
ch[2] );
strNew.Add( &ch, 1 );
pch += 3;
} else {
strNew.Add( pch, 1 );
pch ++;
}
}
} else {
char* pchStart = pch;
while( *pch >= ' ' && pch < pchNextPart && (!fQuoted || *pch !=
'\"') ) {
pch ++;
}
strNew.Add( pchStart, (int)pch - (int)pchStart );
}
if( *pchNextPart != ';' ) {
// 置き換え。ただし改行も入れる。
int cchDecrease = (int)pchNextPart - (int)pchParamName - strNew.
GetLength() - 2;
memcpy( pchParamName, strNew.Direct(), strNew.GetLength() );
memcpy( pchParamName + strNew.GetLength(), szCRLF, 2 );
memcpy( pchParamName + strNew.GetLength() + 2, pchNextPart, cb +
1 - ( (int)pchNextPart - (int)pb ) );
cb -= cchDecrease;
fReplaced = TRUE;
break;
}
}
return fReplaced;
}
|
|