- 论坛徽章:
- 0
|
回复 #5 Godbach 的帖子
不好意思,那天有事临时走了.关于popen还是没有弄懂 我贴下部分代码.
for ( j=0 ; j<user_list.user_num; j++)
{
snprintf(buffer,1024,"%s@%s",user_list.node[j].uid,domain);
snprintf(cmd_buf, 1024, "%s -f%s@%s %s ", SEND_MAIL_BIN, uid,
domain, buffer);
email_fp = popen(cmd_buf, "w");
if (NULL == email_fp)
{
print_error(ERR_UNKNOWN_ERROR, NULL,style);
return;
}
if ('\0' != *attach_string)
{
snprintf(att_ind_fn, 64, "att.%s", attach_string);
if (0 == stat(att_ind_fn, &fstat))
{
if (0 < fstat.st_size)
{
listfd = open(att_ind_fn, O_RDONLY);
if (-1 != listfd)
{
have_att = 1;
}
}
}
}
now = time(NULL);
init_token(mess_id);
fprintf(email_fp, "Message-ID: <%s@%s>\n", mess_id, domain);
fprintf(email_fp, "From: %s@%s\n", uid, domain);
fprintf(email_fp, "To: %s\n", buffer);
fprintf(email_fp, "Subject: %s\n", subject_str);
fprintf(email_fp, "X-Priority: %s\n",priority_str);
if(atoi(read_receipt))
{
fprintf(email_fp, "Disposition-Notification-To: %s@%s\n",uid,domain);
}
if(atoi(receipt))
{
fprintf(email_fp, "Return-Receipt-To: %s@%s\n",uid,domain);
}
rf2822_fmt_date(&now, datebuf);
fprintf(email_fp, "Date: %s\n", datebuf);
if (have_att)
{
gen_boundary(boundary);
fprintf(email_fp, "Content-Type: multipart/mixed;\n\tboundary=\"%s\"\n\n", boundary);
fprintf(email_fp, "Content-Type: text/plain;\n\n");
fprintf(email_fp, "This is a multi-part message in MIME format.\n\n");
fprintf(email_fp, "--%s\nContent-Type: text/plain;\n\n", boundary);
}
else
{
if(!strcmp(html_buf,"true"))
{
fprintf(email_fp, "--%s\nContent-Type: text/html;charset=\"gb2312\"\nContent-Transfer-Encoding: base64\n\n", boundary);
}
else
{
fprintf(email_fp, "Content-Type: text/plain;charset=\"gb2312\"\nContent-Transfer-Encoding: base64\n\n");
}
}
这个是邮件中发信的一部分程序.popen中的 cmd_buf 是qmail中的发信程序.而email_fp 这个文件描述符中的内容是信件的内容.是cmd_buf要发送的内容.这个应该算把fp当成command的输入吧? |
|