邮件高手,请帮帮忙!
我接收到的一个待附件的邮件,用记事本打开为以下:
x-sender: seaboat@cmsland.com
x-receiver: cococut@cmsland.com
Received: from mail pickup service by webserver.landserver with Microsoft SMTPSVC;
Tue, 7 Aug 2001 09:16:15 +0800
From: "seaboat" <seaboat@cmsland.com>
To: <cococut@cmsland.com>
Cc:
Subject: good luck!
Date: Tue, 7 Aug 2001 09:16:13 +0800
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
Message-ID: <WEBSERVER9xDCXobbcs00000001@webserver.landserver>
X-OriginalArrivalTime: 07 Aug 2001 01:16:15.0117 (UTC) FILETIME=[8DA6B3D0:01C11EDE]
你好,baby,还好吗?
begin 666 朋友.txt
0R.>Y^\[2U>:UQ+"NQ..CH0``
`
end
现在我想把乱码部分解码,我把 朋友.txt 后面的部分读进缓冲中,调用以下函数:
char six2pr[64] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z',
'0','1','2','3','4','5','6','7','8','9','+','/'
};
unsigned char pr2six[256];
int HTUU_decode(char *bufcoded, unsigned char *bufplain, int outbufsize)
{
#define DEC(c) pr2six[(int)c]
#define MAXVAL 63
static int first = 1;
int nbytesdecoded, j;
register char *bufin = bufcoded;
register unsigned char *bufout = bufplain;
register int nprbytes;
/* If this is the first call, initialize the mapping table.
* This code should work even on non-ASCII machines.
*/
if(first) {
first = 0;
for(j=0; j<256; j++)
pr2six[j] = MAXVAL+1;
for(j=0; j<64; j++)
pr2six[(int)six2pr[j]] = (unsigned char) j;
}
/* Strip leading whitespace. */
while(*bufcoded==' ' ¦¦ *bufcoded == '\t') bufcoded++;
/* Figure out how many characters are in the input buffer.
* If this would decode into more bytes than would fit into
* the output buffer, adjust the number of input bytes downwards.
*/
bufin = bufcoded;
//while(pr2six[(int)*(bufin++)] <= MAXVAL);
while(pr2six[(int)*bufin] <= MAXVAL)
bufin++;
nprbytes = bufin - bufcoded - 1;
nbytesdecoded = ((nprbytes+3)/4) * 3;
if(nbytesdecoded > outbufsize) {
nprbytes = (outbufsize*4)/3;
}
bufin = bufcoded;
while (nprbytes > 0) {
*(bufout++) = (unsigned char) (DEC(*bufin) << 2 ¦ DEC(bufin[1]) >>4);
*(bufout++) = (unsigned char) (DEC(bufin[1]) << 4 ¦ DEC(bufin[2]) >> 2);
*(bufout++) = (unsigned char) (DEC(bufin[2]) << 6 ¦ DEC(bufin[3]));
bufin += 4;
nprbytes -= 4;
}
if(nprbytes & 03) {
if(pr2six[(int)bufin[-2]] > MAXVAL) {
nbytesdecoded -= 2;
} else {
nbytesdecoded -= 1;
}
}
return(nbytesdecoded);
}
可是怎么也无法揭开,在while (nprbytes > 0循环中,nprbytes始终为2,
怎么回事?请各位高手帮忙!