动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 邮件系统软件 > Qmail
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Qmail ]的信息

本月文章推荐
.Postfix + Courier-IMAP + Cyrus.
.postfix邮件系统的调试.
.vpopmail+spamassassin+clamscan.
.Qmail邮件系统下防止滥用mail re.
.用Sendmail配置你的第一台e-mail.
.Qmail如何做用户伪装.
.限制特定用户收发邮件的高级访问.
.Qmail的安装调试.
.QMAIL邮件管理篇VmailMgr.
.Liunx架站之架设Mail服务器.
.域名和邮件服务器FAQ.
.FreeBSD下E-mail服务搭建.
.如何一次创建大量用户.
.监控你E-mail用户的邮件(sendma.
.Maildrop的若干常见问题集锦(FA.
.Qmail 的主要配置文件.
.邮件列表黄金搭档—Qmail+Ezmlm.
.Postfixadmin ( Web GUI 虛擬郵件.
.给qmail服务器增加个防病毒网关.
.Clamav + Amavisd-new + Spamass.

qmail-qfilter的使用及代码框架

发表日期:2006-12-3 |


前几天刚好用到,所以整理了一下, 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 can't create the temporary files or
has problems executing the filters. Returns 91 (bad enve-
lope data) if it can't 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 OS's doesn't 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目录. ,
上一篇:qmail源代码分析之qmail-pop3d 人气:2650
下一篇:商用Sendmail的安全和隔离要点 人气:1817
浏览全部Qmail/Sendmail/Postf的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-9-6 Movie34电影搜索引擎 v3.0
2008-9-6 wap2.0仿帝国建站喜用 v2.0
2008-9-6 免费人才招聘网 宽屏版 v3.01
2008-9-6 喜喔喔视频采集程序 v1.0 beta
2008-9-6 ASP客户管理系统
2008-9-6 主流驿站中秋祝福程序
2008-9-6 php实现msn协议的类
2008-9-5 Coppermine Photo Gallery v1.4.
2008-9-5 清松网络日记本 v2.4
2008-8-23 Mini WinMount V0.4
2008-8-23 Vista优化大师3.11正式版
2008-8-23 Wine 1.13
2008-8-23 KlipFolio 5.0 Build 5899-80
2008-8-23 Windows Sysinternals Desktops
2008-8-23 OneTap Movies1.2破解版
2008-8-23 AnnotaterPDF阅读1.1.503 破解版
2008-8-23 SoundMeter分贝测量仪 v1.0汉化破
2008-8-23 iDrum音乐节拍1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | Html转换js | js/vbs加密 | md5加密 | 进制转换
实用工具:汉字翻译拼音 | 符号对照表 | 个税计算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号