原始邮件内容格式探问?

发布于 2022-05-27 18:14:43 字数 101 浏览 12 评论 4

处理原始邮件内容时会碰到MIME格式,它是什么意思?和字符集(“GB212""繁体"等)又有什么关系?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一张白纸-° 2022-06-03 12:08:35

MIME 格式是一种压缩与解压缩的算法,SMTP 都用它,如果需要我可以给你两个源文件,很简单的

秉烛思 2022-06-03 07:16:41

#ifndef _MIME_H
#define _MIME_H

#define MIMELINELEN 72

/* bit values for MimeMode */
#define MM_CVTMIME 0x0001 /* convert 8 to 7 bit MIME */
#define MM_PASS8BIT 0x0002 /* just send 8 bit data blind */
#define MM_MIME8BIT 0x0004 /* convert 8-bit data to MIME */

/*
** Flags passed to mime8to7.
*/

#define M87F_OUTER 0 /* outer context */
#define M87F_NO8BIT 0x0001 /* can't have 8-bit in this section */
#define M87F_DIGEST 0x0002 /* processing multipart/digest */
#define M87F_NO8TO7 0x0004 /* don't do 8->7 bit conversions */

int MimeInit();
int MimeEnd();

size_t mime8to7(char *buf , char *data , long st);
size_t mime7to8(char *buf , char *data , long st);

#endif

#include "stdafx.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "mime.h"

static char Base64Code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

int isbase64code(int c)
{
//return ((strchr(Base64Code,c) == NULL) || ( c == 0) ? 0 : 1);
if(c!='='){
if(strchr(Base64Code,c)==NULL)
return 0;
if(c==0)
return 0;
}
return 1;
}

/*
*Encode
*/
size_t mime8to7(char *buf , char *data , long st)
{
unsigned char c1,c2;
register char *p;
register char *bp;
char bbuf[128]; //keep every line
long linelen; //only for splite line
long len;

*bbuf=0;
p=data;
bp=buf;
linelen = 0;

while( p - data < st)
{
c1 = *p++;
/*
if (linelen >= MIMELINELEN) //every line = 72
{
*bp = '';
buf = putline(buf, bbuf);
linelen = 0;
bp = bbuf;
}
linelen += 4;
*/

*bp++ = Base64Code[(c1 >> 2)];
c1 = (c1 & 0x03) << 4;

if (p - data >= st)
{
*bp++ = Base64Code[c1];
*bp++ = '=';
*bp++ = '=';
break;
}
else
c2 = *p++;

c1 |= (c2 >> 4) & 0x0f;
*bp++ = Base64Code[c1];
c1 = (c2 & 0x0f) << 2;

if (p - data >= st)
{
*bp++ = Base64Code[c1];
*bp++ = '=';
break;
}
else
c2 = *p++;

c1 |= (c2 >> 6) & 0x03;
*bp++ = Base64Code[c1];
*bp++ = Base64Code[c2 & 0x3f];
}
*bp = '';
len = bp - buf;
//printf("%sn",buf);
//putline(buf, bbuf);
return len;
}
/*
*decode
*/
static char index_64[128] =
{
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
};

#define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)])

size_t mime7to8(char *buf , char *data , long st)
{
unsigned char c1,c2,c3,c4;
register char *p;
register char *fbufp;
long len;

len = 0;
fbufp = buf;
p = data;

//printf("st: %ldn",st);

while ( p - data <= st)
{
//printf("%d ",p-data);
c1 = *p++;
if (!isbase64code(c1))
continue;

do
{
if (p - data > st)
break;
else
c2 = *p++;
} while (!isbase64code(c2));
if (p - data > st)
break;

do
{
if (p - data > st)
break;
else
c3 = *p++;
} while (!isbase64code(c3));
if (p - data > st)
break;

do
{
if (p - data > st)
break;
else
c4 = *p++;
} while (!isbase64code(c4));
if (p - data > st)
break;

if (c1 == '=' || c2 == '=')
continue;

c1 = CHAR64(c1);
c2 = CHAR64(c2);

*fbufp = (c1 << 2) | ((c2 & 0x30) >> 4);
fbufp++;

if (c3 == '=')
continue;

c3 = CHAR64(c3);
*fbufp = ((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2);
fbufp++;
if (c4 == '=')
continue;

c4 = CHAR64(c4);
*fbufp = ((c3 & 0x03) << 6) | c4;
fbufp++;
}
*fbufp = '';

len = fbufp - buf;
return len;
}

-残月青衣踏尘吟 2022-05-31 05:50:32

谢谢patrickgamp2,可否简单说一下程序处理的内容?
MIME是不是有多种编码方法:Base64,QP,8-bit。请问您的程序是对那种编码有效。

白云悠悠 2022-05-29 11:50:24

Base64,其实你细看一下程序就知道了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文