分享
 
 
 

qmail-qfilter的使用及代码框架

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

前几天刚好用到,所以整理了一下, 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目录. ,

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有