RT

解决方案 »

  1.   

    简单得很,base64编码。#define cBASE64PAD '='char* CBase64::szBase64Table=
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    "abcdefghijklmnopqrstuvwxyz"
    "0123456789+/";int CBase64::Encode(char* orig, int len, char* base64, int size)
    {
    if(size < EncodeSize(len))
    return -1;
    char* current=orig;
    int i=0;
    while(len > 2)
    {
    base64[i++] = szBase64Table[current[0] >> 2];
    base64[i++] = szBase64Table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
    base64[i++] = szBase64Table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
    base64[i++] = szBase64Table[current[2] & 0x3f];
    current += 3;
    len -= 3;
    }
    if(len != 0)
    {
    base64[i++] = szBase64Table[current[0] >> 2];
    if (len > 1)
    {
    base64[i++] = szBase64Table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
    base64[i++] = szBase64Table[(current[1] & 0x0f) << 2];
    base64[i++] = cBASE64PAD;
    }
    else
    {
    base64[i++] = szBase64Table[(current[0] & 0x03) << 4];
    base64[i++] = cBASE64PAD;
    base64[i++] = cBASE64PAD;
    }
    }
    return i;
    }int CBase64::Decode(char* base64, int len, char* orig, int size)
    {
    if(size < DecodeSize(len))
    return -1;
    int c;
    int i; //index of base64
    int j=0; //index of orig
    for(i=0; i<len; i++)
    {
    c=base64[i];
    if(c==cBASE64PAD)
    break;
    c=(int)strchr(szBase64Table, c);
    if(c==0)
    return -1;
    c-=(int)szBase64Table;
    switch(i & 0x03) //i%4
    {
    case 0:
    orig[j] = c << 2;
    break;
    case 1:
    orig[j++] |= c >> 4;
    orig[j] = (c & 0x0f) << 4;
    break;
    case 2:
    orig[j++] |= c >> 2;
    orig[j] = (c & 0x03) << 6;
    break;
    case 3:
    orig[j++] |= c;
    break;
    }
    }
    if(c == cBASE64PAD)
    {
    switch(i & 0x03) //i % 4
    {
    case 0:
    case 1:
    return -1;
    case 2:
    j++;
    case 3:
    // j++;
    break;
    }
    }
    return j;
    }
      

  2.   

    忘了,两个inline的东西static int EncodeSize(int nOrigSize)
    {
    return ((nOrigSize + 2) / 3) << 2;
    }
    static int DecodeSize(int nBase64Size)
    {
    return nBase64Size / 4 * 3;
    }
      

  3.   

    谢谢 ndy_w(carpe diem)不过你说的也太简单了吧,我指的是如果将一个邮件的原始信息存成一个.msg文件,能将邮件的信息以及附件等从中解析出来的整个代码;
      

  4.   

    mime++ 1.0是公开的源码的,网上可以搜到
      

  5.   

    to kingbird(core dump):
    没有找到源代码啊,那个网站没提供源代码,你有吗?
      

  6.   

    upqp编码解码的部分的MIME++里面好像也有;
      

  7.   

    mime++ 1.0好像很难用啊,有谁用过吗