???电子邮件中的'附件'功能是如何实现的???

linlin 2000-09-14 09:01:00
有谁知道电子邮件中的'附件功能'是如何实现的??
我看了看163中的附件功能,发现它只需要知道客户端的IP地址和文件名,就可以实现。
请问,服务器端是如何仅通过客户端的IP地址和文件名就能得到该文件??
...全文
259 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunxiaobin123 2000-12-04
  • 打赏
  • 举报
回复
char *getshortfilename(char *data)
{
char *p1=NULL,*p2=NULL;
if((p1=strstr(data,"filename="))==NULL) return NULL;
p1+=strlen("filename=");
if(!p1) return NULL;
htmldecode(p1);
quotestospace(p1);
trim(p1);
if (!p1 || strlen(p1) < 1) return NULL;
p2=p1;
while (*p1)
{
if (*p1 == '\\' || *p1 ==':'|| *p1 == '/')
p2=p1+1;
p1++;
}
if (!p2 || strlen(p2) < 1) return NULL;
else return strdup(p2);
}

int SaveFile(char *b, char *name)

/* read from stdin ,put data into a temp file
* b is boundary string,use it to end an input
* name in here now is not used
*/
{
char key;
FILE * out;
long size = 0;
char enddata[MAXBOUNDARYLEN];
char fullpath[MAX_DIRLEN];
int index = 0,i;

sprintf(enddata, "%c%c%s", 0x0d, 0x0a, b);
sprintf(fullpath, "%s/%s/%s", useronlineinfo.homedirectory,DOWNLOAD,name);
out = fopen(fullpath, "w+");
if (out == NULL) return 0;
while (fread(&key, 1, 1, stdin))
{
if (enddata[index] == '\0') break;
else if (key == enddata[index]) index++;
else
{
for (i = 0; i < index; i++)
{
fwrite(&enddata[i], 1, 1, out);
size++;
}
index = 0;
if (key == enddata[index])
index++;
else
{
fwrite(&key, 1, 1, out);
size++;
}
}
}
fflush(out);
fclose(out);
return 1;
}

void attachadd()
{
char boundary[MAXBOUNDARYLEN];
char newboundary[MAXBOUNDARYLEN];
char *env,*p;
unsigned char data[500];
FILEINFO fileinfo;
char attachmentlistfilename[MAX_DIRLEN];
FILE *fp=NULL;
if ((env = getenv("HTTP_USER_AGENT")) == NULL
|| (strncasecmp(env, "Mozilla/4", 9) != 0 && strncasecmp(env, "Mozilla/3", 9) != 0)
)
{
error(_FILE_UPLOAD_NOT_SUPPORT_);
return;
}
if ((env=getenv("CONTENT_TYPE"))==NULL||(p=strstr(env, "boundary="))==NULL)
{
error(_CANNOT_FIND_BOUNDARY_);
return;
}
p+=strlen("boundary=");
if(!p || strlen(p)<1)
{
error(_CANNOT_FIND_BOUNDARY_);
return;
}
trim(p);sprintf(boundary,p);
sprintf(newboundary, "--%s", boundary);
memset(&fileinfo,0,sizeof(fileinfo));
while (fgets(data, sizeof(data), stdin) != NULL)
{

if (strncasecmp (data, "Content-Disposition: ", 21)==0
&& strstr ((char *) data, "name=") != NULL
&& strstr ((char *) data, "filename=") != NULL)
{
fileinfo.filename=getshortfilename(data);

if (!fileinfo.filename || strlen(fileinfo.filename)<1) break;

if(fgets(data, sizeof(data), stdin) != NULL && strncasecmp(data,"Content-Type: ",14)==0)
{ fileinfo.filetype=strdup(data+14);
trim(fileinfo.filetype);
}

while(AttachmentFileNameExist(fileinfo.filename))
{
p=malloc(strlen(fileinfo.filename)+5);
sprintf(p,"cp_%s",fileinfo.filename);free(fileinfo.filename);
fileinfo.filename=p;
}

while (fgets(data, sizeof(data) , stdin) != NULL)
if ((char)data[0] == '\n' || (char)data[0] == '\r') break;

sprintf(attachmentlistfilename,"%s/%s",useronlineinfo.homedirectory,ATTACHMENTLISTFILE);
fp = fopen(attachmentlistfilename, "a");
if(fp!=NULL )
{
SaveFile(newboundary, fileinfo.filename);
WriteAttachmentList(fp,&fileinfo);
fflush(fp);
fclose(fp);
}
FreeFileinfo(&fileinfo);
}
}
sprintf(NextURL,"%s?attach",attachmenturl);
GotoURL(NextURL);
return;
}
看看原吗吧....
godspeed_g 2000-10-07
  • 打赏
  • 举报
回复
看一看网页的HTML源代码,
上传文件使用了一个FILE类型的INPUT控件,
这个INPUT控件使用了enctype="multipart/form-data"属性设置
在点击提交按钮时,浏览器就会按照一定的格式把文件名称、内容传到服务器!
linlin 2000-09-14
  • 打赏
  • 举报
回复
其实就是如何实现上载功能。

4,356

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧