首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 冲浪宝典-> 联络聊天
qmail-qfilter的使用及代码框架_qmail
作者:网友供稿 点击:0
推荐
西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!可在线rar解压,自动数据恢复设置虚拟目录等.免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金
站内搜索
文章页数:[1] 
前几天刚好用到,所以整理了一下, POST上来让大家扔砖头。 最近对邮件过滤和邮件网关有点兴趣,有没有有经验兄弟交流一把?站内联系.

+++++++++++++++++++++
一. 使用
1) qmail-queue patch

2) 修改tcp.smtp文件, 设置环境变量
127.0.0.1:allow,RELAYCLIENT="",QMAILQUEUE="/var/qmail/bin/filter"
:allow,QMAILQUEUE="/var/qmail/bin/filter"

3) 生成/var/qmail/bin/filter脚本:权限4755, 属主qmailq.qmail.
脚本中的各个filter以--分隔.

#!/bin/bash
exec /var/qmail/bin/qmail-qfilter /var/qmail/qqfilter/logfilter -- /var/qmail/qqfilter/procmail 2>/tmp/procmail
#-- /var/qmail/bin/qmail-inject -n

4) 可生成一新的目录/var/qmail/qqfilter存放所有的filter programs.

二. 文档

qmail-qfilter sends the message text through each of the
filter commands named on the command line. Each filter is
run seperately, with standard input opened to the input
email, and standard output opened to a new temporary file
that will become the input to either the next filter, or
qmail-queue. Each filter on the command line in seperated
with --.

Returns 51 (out of memory), 53 (write error), or 81
(internal error) if it cant create the temporary files or
has problems executing the filters. Returns 91 (bad enve-
lope data) if it cant read or parse the envelope data.
If a filter returns anything other than 0 or 99, qmail-
qfilter returns its exit code. If a filter returns 99,
qmail-qfilter returns 0 immediately without running any
other filters. Otherwise returns the exit code of qmail-
queue.

qmail-qfilter sets QMAILUSER and QMAILHOST to the user and
host portions of the envelope sender address, and unsets
QMAILNAME. It also sets QMAILRCPTS to the list of enve-
lope recipients, each followed by a newline.

If you are using qmail-inject -n as one of the filters,
you may want to unset MAILUSER, USER, and LOGNAME by using
env -u QMAILNAME -u MAILNAME -u NAME qmail-inject -n as
the command to invoke qmail-inject. Note that some the
env command with some OSs doesnt support the -u option.

A message with an excessive number of recipients (more
than 64K bytes of recipient data on Linux) will cause exe-
cution of the filter programs to fail, and for the message
to be rejected.

三. 代码
1. 参数解析
struct command
{
char** argv;
struct command* next;
};
typedef struct command command;

command* filters;
filters = parse_args(argc-1, argv+1);
// 所有的filter programs存放到filters链表, 执行脚本中各个filter program以--分隔.



2. 邮件原文处理
/* Copy the message from FD0 to the first temporary file */
int copy_message()
将邮件原文读取到临时文件中, 文件指针指向开头, 返回tmpfd.



3. 信封地址处理

static const char* env = 0;
static size_t env_len = 0;

结构:
struct bufchain
{
size_t len;
char* buf;
struct bufchain* next;
};


/* Read the envelope from FD 1, and parse the sender address */
bool read_envelope()
{
从FD 1读取信封信息, 每读一次存放到bufchain, 最后拷贝到env中, env_len相应赋值, 释放bufchain链表.
return parse_envelope();
// 解析信封信息, 存储到环境变量QMAILUSER, QMAILHOST, QMAILRCPTS后传递给filter program
}



4. 调用filter program:
tmpfd = run_filters(filters, tmpfd);

循环filters链表, 依次执行每个filter program:
父进程生成一个临时文件fdout, 派生子进程执行filter program,
子进程使用tmpfd作为标准输入, fdout作为标准输出.
父进程等待子进程结束, 关闭tmpfd, 将该filter program的标准输出fdout的文件指针指向开头后作为新的tmpfd, 继续下一个filter program.

循环结束后返回tmpfd(所有filter program执行过后的输出).



5. 派生子进程运行qmail-queue:

子进程:
run_qmail_queue(tmpfd, envpipe);
qmail-queue关闭0, 1, envpipe[1];
qmail-queue从tmpfd读取邮件原文;
从envpipe[0]读取信封信息;

父进程:
关闭envpipe[1], 写信封信息到envpipe[0], 关闭envpipe[0];
waitpid()等待qmail-queue结束.



6. filter program例子.
见qmail-qfilter源代码samples目录. ,

文章整理:站长天空 网址:http://www.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·Java Unicode转义字符的小小研究-JSP教程,Java技巧及代码
·实现VB与EXCEL的无缝连接-.NET教程,VB.Net语言
·在ASP.NET里通过URL传递参数得到乱码的解决方法-ASP教程,ASP应用
·实例讲解:Java中的SOAP技术-JSP教程,Java技巧及代码
·Session过期问题-ASP教程,ASP应用
·设计模式笔记-抽象工厂模式-.NET教程,评论及其它
·JSP标准标记库促进了网页的开发-JSP教程,Jsp/Servlet
·在Remoting Server上取得Remoting Client的IP地址-ASP教程,ASP应用
·使用JSP标记库校验用户输入-JSP教程,Jsp/Servlet
·c#中DataGrid的数据新增编辑删除操作代码-.NET教程,数据库应用
最新文章
·xp也能享受vista readyboost闪存加速_windows xp
·c# 3.0新特性系列:隐含类型var_c#教程
·如此做google广告,月赚10万美金不成问题_网赚技巧
·王通:个人博客的赚钱之道_网赚技巧
·这一年来风风雨雨-再访中客宋陈磊_站长访谈
·个人网站的定位推广和赚钱-访中国建站站长_站长访谈
·祥瑞网方文春:从800元到6000万元_站长访谈
·行业类、专业性成功网站给个人站长的启示_站长访谈
·网站推广 新招老招齐用上_站长心得
·widnows vista工具栏添加快速启动tabletpc图标_windows vista
相关主题
  • qmail+vpopmail+mysql+qmailadmin+ezmlm+igenus构建企业邮局_qmail
  • qmail邮件系统安装(freebsd 3.4)_qmail
  • qmail邮件系统下防止滥用mail relay完全解决方案_qmail
  • qmail使用smtp发信的设置问题集_qmail
  • qmail+vpopmail邮件过滤(练习篇)_qmail
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭