pike.git / lib / modules / Protocols.pmod / SMTP.pmod / module.pmod

version» Context lines:

pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:7:    214:"Help message",    220:"<host> Service ready",    221:"<host> Service closing transmission channel",    250:"Requested mail action okay, completed",    251:"User not local; will forward to <forward-path>",    252:"Cannot VRFY user, but will accept message and attempt delivery",    354:"Start mail input; end with <CRLF>.<CRLF>",    421:"<host> Service not available, closing transmission channel "    "[This may be a reply to any command if the service knows it "    "must shut down]", +  454:"TLS not available due to temporary reason",    450:"Requested mail action not taken: mailbox unavailable "    "[E.g., mailbox busy]",    451:"Requested action aborted: local error in processing",    452:"Requested action not taken: insufficient system storage",    500:"Syntax error, command unrecognized "    "[This may include errors such as command line too long]",    501:"Syntax error in parameters or arguments",    502:"Command not implemented",    503:"Bad sequence of commands",    504:"Command parameter not implemented",
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:56:       int i;    tokens = tokens[search(tokens, '<') + 1..];       if ((i = search(tokens, '>')) != -1) {    tokens = tokens[..i-1];    }    return tokens*"";    }    -  //! Return an RFC2822 date-time string suitable for the @tt{Date:@} header. +  //! Return an @rfc{2822@} date-time string suitable for the +  //! @tt{Date:@} header.    string rfc2822date_time(int ts)    {    mapping(string:int) lt = localtime(ts);    int zsgn = sgn(lt->timezone);    int zmin = (zsgn * lt->timezone)/60;    int zhr = zmin/60;    zmin -= zhr*60;    int zone = -zsgn*(zhr*100 + zmin);    return sprintf("%s, %02d %s %04d %02d:%02d:%02d %+05d",    ({ "Sun", "Mon", "Tue", "Wed", "Thu",
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:100:    default:    error( "SMTP: "+c+"\n"+(comment?"SMTP: "+comment+"\n":"")+    "SMTP: "+replycodes[r]+"\n" );    }    return r;    }       //! @decl void create()    //! @decl void create(Stdio.File server)    //! @decl void create(string server, void|int port) -  //! Creates an SMTP mail client and connects it to the -  //! the @[server] provided. The server parameter may -  //! either be a string with the hostname of the mail server, -  //! or it may be a file object acting as a mail server. -  //! If @[server] is a string, then an optional port parameter -  //! may be provided. If no port parameter is provided, port -  //! 25 is assumed. If no parameters at all is provided -  //! the client will look up the mail host by searching -  //! for the DNS MX record. +     //! -  +  //! Creates an SMTP mail client and connects it to the the @[server] +  //! provided. The server parameter may either be a string with the +  //! hostname of the mail server, or it may be a file object acting +  //! as a mail server. If @[server] is a string, then an optional +  //! port parameter may be provided. If no port parameter is +  //! provided, port 25 is assumed. If no parameters at all is +  //! provided the client will look up the mail host by searching for +  //! the DNS MX record. +  //!    //! @throws    //! Throws an exception if the client fails to connect to    //! the mail server.    void create(void|string|Stdio.File server, int|void port)    {    if(!server)    {    // Lookup MX record here (Using DNS.pmod)    object dns=master()->resolv("Protocols")["DNS"]->client();    server=dns->get_primary_mx(gethostname());
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:163:    token = map(token/".", Standards.IDNA.to_ascii) * ".";    } else {    token = string_to_utf8(token);    }    tokens[i] = token;    }       return MIME.quote(tokens);    }    -  //! Sends a mail message from @[from] to the mail addresses -  //! listed in @[to] with the mail body @[body]. The body -  //! should be a correctly formatted mail DATA block, e.g. -  //! produced by @[MIME.Message]. +  //! Sends a mail message from @[from] to the mail addresses listed +  //! in @[to] with the mail body @[body]. The body should be a +  //! correctly formatted mail DATA block, e.g. produced by +  //! @[MIME.Message].    //!    //! @seealso    //! @[simple_mail]    //!    //! @throws    //! If the mail server returns any other return code than    //! 200-399 an exception will be thrown.    void send_message(string from, array(string) to, string body)    {    cmd("MAIL FROM: <" + punycode_address(from) + ">");
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:454:    new[substitute_callback_rec(k, server)] = substitute_callback_rec(m[k], server);    }    return new;   #endif    } else    {    return m;    }    }    -  //! Creates an SMTP mail client and connects it to the -  //! the @[server] provided. The server parameter may -  //! either be a string with the hostname of the mail server, -  //! or it may be a file object acting as a mail server. -  //! If @[server] is a string, then an optional port parameter -  //! may be provided. If no port parameter is provided, port -  //! 25 is assumed. If no parameters at all is provided -  //! the client will look up the mail host by searching -  //! for the DNS MX record. +  //! Creates an SMTP mail client and connects it to the the @[server] +  //! provided. The server parameter may either be a string with the +  //! hostname of the mail server, or it may be a file object acting +  //! as a mail server. If @[server] is a string, then an optional +  //! port parameter may be provided. If no port parameter is +  //! provided, port 25 is assumed. If no parameters at all is +  //! provided the client will look up the mail host by searching for +  //! the DNS MX record.    //! -  //! The callback will first be called when the connection is established -  //! (@expr{cb(1, @@args)@}) or fails to be established with an error. The -  //! callback will also be called with an error if one occurs during the -  //! delivery of mails. +  //! The callback will first be called when the connection is +  //! established (@expr{cb(1, @@args)@}) or fails to be established +  //! with an error. The callback will also be called with an error if +  //! one occurs during the delivery of mails.    //!    //! In the error cases, the @expr{cb@} gets called the following ways:    //! @ul    //! @item    //! @expr{cb(({ 1, errno(), error_string, int(0..1) direct }), @@args);@}    //! @item    //! @expr{cb(({ 0, smtp-errorcode, error_string, int(0..1) direct }), @@args);@}    //! @endul    //! Where @expr{direct@} is @expr{1@} if establishment of the connection    //! failed.
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:489:    function|void cb, mixed ... args)    {    object dns=master()->resolv("Protocols")["DNS"];       if (objectp(server)) {    if (Program.inherits(object_program(server), Protocols.SMTP.AsyncClient)) {    if (!port) port = server->port;    if (!cb) cb = server->cb;    if (!args) args = server->args;    object t = server->server; -  this_program::port = port; -  this_program::args = args; -  this_program::cb = cb; +  this::port = port; +  this::args = args; +  this::cb = cb;       // fetch queue    foreach(server->error_cbs; function f; array args)    {    error_cbs[substitute_callback(f, server)] = args;    }    error_cb = server->error_cb && substitute_callback(server->error_cb, server);    error_args = server->error_args;    //sequences = map(server->sequences, substitute_callback, server);    sequences = substitute_callback_rec(server->sequences, server);       destruct(server); -  this_program::server = server = t; +  this::server = server = t;    initiate_connection(server, port, cb, @args);    return;    }    }    -  this_program::server = server; -  this_program::port = port; -  this_program::cb = cb; -  this_program::args = args; +  this::server = server; +  this::port = port; +  this::cb = cb; +  this::args = args;       if(!error_cbs[cb]) error_cbs[cb] = ({ });    error_cbs[cb] += ({ args });       if(!server)    {    // Lookup MX record here (Using DNS.pmod)    dns->async_get_mx(gethostname(), lambda(array a)    {    if (a)
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:1013:       // fetch the email address from the mail from: or rcpt to: commands    // content: the input line like mail from:<toto@caudium.net>    // what: the action either from or to    int|string parse_email(string content, string what)    {    array parts = content / ":";    if(lower_case(parts[0]) != what)    return 500;    string validating_mail; -  parts[1] = String.trim_all_whites(parts[1]); +  parts[1] = String.trim(parts[1]);    if(!sscanf(parts[1], "<%s>", validating_mail))    sscanf(parts[1], "%s", validating_mail);       // Since we relay, we must accept mail for <postmaster> according to RFC 2821.    // If we get mail for postmaster, we rewrite the address to postmaster@mydomain.    if (validating_mail == "postmaster")    validating_mail += "@" + cfg->domains[0];    if(validating_mail == "")    validating_mail = "MAILER-DAEMON@" + cfg->domains[0];    array emailparts = validating_mail / "@";
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:1339: Inside #if defined(SMTP_DEBUG)
  #ifdef SMTP_DEBUG    write("buffposition=%d, inputbuffer=%O\n", bufferposition, inputbuffer);   #endif    bufferposition += sizeof(pattern);    int end = bufferposition-(1+sizeof(pattern));    if(!datamode)    {    launch_functions(inputbuffer[..end]);    if(lower_case(inputbuffer[..end]) == "quit")    { - #if constant(this) +     destruct(this); - #else -  destruct(this_object()); - #endif +     return;    }    pattern = "\r\n";    }    if(datamode)    {    if(pattern=="\r\n.\r\n")    message(inputbuffer[..end]);    pattern = "\r\n.\r\n";    }
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:1433:    fd->write("421 " + replace(replycodes[421], "<host>", localhost)    + "\r\n");    shutdown_fd();    return;    }    //log("connection from %s to %s:%d", remoteaddr, localaddr, localport);    fd->set_nonblocking(read_cb, write_cb, close_cb);    call_out(handle_timeout, 300, "'First connexion'");    }    -  void destroy() +  protected void _destruct()    {    shutdown_fd();    }      };      //! The use of Protocols.SMTP.server is quite easy and allow you   //! to design custom functions to process mail. This module does not   //! handle mail storage nor relaying to other domains.   //! So it is your job to provide mail storage and relay mails to other servers
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:1458:       protected void accept_callback()    {    object fd = fdport->accept();    if(!fd)    error("Can't accept connections from socket\n");    Connection(fd, config);    destruct(fd);    }    -  //! @decl void create(array(string) _domains, void|int port,@ -  //! void|string ip, function _cb_mailfrom,@ -  //! function _cb_rcptto, function _cb_data) -  //! Create a receiving SMTP server. It implements RFC 2821, 2822 and 1854. +  //! Create a receiving SMTP server. It implements @rfc{2821@}, +  //! @rfc{2822@} and @rfc{1854@}.    //!    //! @param 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.    //! @param port    //! Port this server listen on    //! @param listenip    //! IP on which server listen
pike.git/lib/modules/Protocols.pmod/SMTP.pmod/module.pmod:1526:    //! }    //! return 250;    //! }    //!    //! int main(int argc, array(string) argv)    //! {    //! Protocols.SMTP.Server(({ "ece.fr" }), 2500, "127.0.0.1", @    //! cb_mailfrom, cb_rcptto, cb_data);    //! return -1;    //! } -  void create(array(string) _domains, void|int port, void|string ip, function _cb_mailfrom, -  function _cb_rcptto, function _cb_data) +  void create(array(string) domains, void|int port, void|string ip, +  function cb_mailfrom, function cb_rcptto, function cb_data)    { -  config = Configuration(_domains, _cb_mailfrom, _cb_rcptto, _cb_data); -  random_seed(getpid() + time()); +  config = Configuration(domains, cb_mailfrom, cb_rcptto, cb_data);    if(!port)    port = 25;    fdport = Stdio.Port(port, accept_callback, ip);    if(!fdport)    {    error("Cannot bind to socket, already bound ?\n");    }    }   };