Class Protocols.LMTP.Server

Description

A LMTP server. It has been fairly well tested against Postfix client. Actually this module is only an extention to the SMTP server.

It implements RFC 2821, RFC 2822, RFC 2033 and RFC 1854.


Method create

Protocols.LMTP.Server Protocols.LMTP.Server(array(string) _domains, void|int port, void|string ip, function(:void) _cb_mailfrom, function(:void) _cb_rcptto, function(:void) _cb_data)

Description

Create a receiving LMTP server.

Parameter domain

Domains name this server relay, you need to provide at least one domain (the first one will be used for MAILER-DAEMON address). if you want to relay everything you can put a '*' after this first domain.

Parameter port

Port this server listen on

Parameter listenip

IP on which server listen

Parameter cb_mailfrom

Mailfrom callback function, this function will be called when a client send a mail from command. This function must take a string as argument (corresponding to the sender's email) and return int corresponding to the SMTP code to output to the client. If you return an array the first element is the SMTP code and the second is the error string to display.

Parameter cb_rcptto

Same as cb_mailfrom but called when a client sends a rcpt to.

Parameter cb_data

This function is called for each recipient in the "rcpt to" command after the client sends the "data" command It must have the following synopsis: int|array cb_data(object mime, string sender, string recipient, void|string rawdata) object mime : the mime data object string sender : sender of the mail (from the mailfrom command) string recipient : one recipient given by one rcpt command. return : SMTP code to output to the client. If you return an array the first element is the SMTP code and the second is the error string to display. Note that to comply with LMTP protocol you must output a code each time this function is called.

Example

Here is an example of silly program that does nothing except outputing informations to stdout. int cb_mailfrom(string mail) { return 250; }

int cb_rcptto(string email) { // check the user's mailbox here return 250; }

int cb_data(object mime, string sender, string recipient) { write(sprintf("smtpd: mailfrom=%s, to=%s, headers=%O\ndata=%s\n", sender, recipient, mime->headers, mime->getdata())); // check the data and deliver the mail here if(mime->body_parts) { { foreach(mime->body_parts, object mpart) write(sprintf("smtpd: mpart data = %O\n", mpart->getdata())); } return 250; }

int main(int argc, array(string) argv) { Protocols.LMTP.Server(({ "ece.fr" }), 2500, "127.0.0.1", cb_mailfrom, cb_rcptto, cb_data); return -1; }