diff -aup orig/Makefile size/Makefile --- orig/Makefile 1998-06-15 12:53:16.000000000 +0200 +++ size/Makefile 2004-05-20 21:36:03.000000000 +0200 @@ -1463,11 +1463,11 @@ tcpto.h readwrite.h timeoutconn.h timeou qmail-rspawn: \ load qmail-rspawn.o spawn.o tcpto_clean.o now.o coe.o sig.a open.a \ seek.a lock.a wait.a fd.a stralloc.a alloc.a substdio.a error.a str.a \ -auto_qmail.o auto_uids.o auto_spawn.o +auto_qmail.o auto_uids.o auto_spawn.o fmt_ulong.o ./load qmail-rspawn spawn.o tcpto_clean.o now.o coe.o \ sig.a open.a seek.a lock.a wait.a fd.a stralloc.a alloc.a \ substdio.a error.a str.a auto_qmail.o auto_uids.o \ - auto_spawn.o + auto_spawn.o fmt_ulong.o qmail-rspawn.0: \ qmail-rspawn.8 diff -aup orig/qmail-lspawn.c size/qmail-lspawn.c --- orig/qmail-lspawn.c 1998-06-15 12:53:16.000000000 +0200 +++ size/qmail-lspawn.c 2004-05-21 00:50:14.976050104 +0200 @@ -165,9 +165,8 @@ char *local; } } -int spawn(fdmess,fdout,s,r,at) -int fdmess; int fdout; -char *s; char *r; int at; +int +spawn(int fdmess, int fdout, const unsigned long msgsize, char *s, char *r, const unsigned int at) { int f; Nur in size: qmail-remote-ESMTP-0.04b.diff. diff -aup orig/qmail-remote.8 size/qmail-remote.8 --- orig/qmail-remote.8 1998-06-15 12:53:16.000000000 +0200 +++ size/qmail-remote.8 2004-05-20 21:36:03.000000000 +0200 @@ -1,10 +1,11 @@ .TH qmail-remote 8 .SH NAME -qmail-remote \- send mail via SMTP +qmail-remote \- send mail via SMTP or ESMTP .SH SYNOPSIS .B qmail-remote .I host .I sender +.I size .I recip [ .I recip ... @@ -40,6 +41,11 @@ or an IP address enclosed in brackets: [128.32.183.163] .EE +The size parameter is only used if the remote host uses the ESMTP SIZE extension defined in +.I RFC 1870\fP. It gives the size of the message in bytes. +.BR qmail-remote +does not use this value to process the mail, the value is only passed to the remote mailserver. + The envelope recipient addresses are listed as .I recip arguments to diff -aup orig/qmail-remote.c size/qmail-remote.c --- orig/qmail-remote.c 1998-06-15 12:53:16.000000000 +0200 +++ size/qmail-remote.c 2004-05-21 00:52:39.270114072 +0200 @@ -2,6 +2,7 @@ #include #include #include +#include #include "sig.h" #include "stralloc.h" #include "substdio.h" @@ -216,23 +217,97 @@ void blast() stralloc recip = {0}; -void smtp() +void +do_helo(char *cmd) +{ + substdio_puts(&smtpto,cmd); + substdio_put(&smtpto,helohost.s,helohost.len); + substdio_put(&smtpto,"\r\n",2); + substdio_flush(&smtpto); +} + +/** + * esmtp_ehlo - find out which ESMTP extensions the remote server supports + * + * returns: a bitmask of the supported extensions on success + * does not return on failure (logs error and quits the process) + */ + +unsigned int +esmtp_ehlo(void) +{ + int search = 0; + int is_esmtp = 1; + int extensions = 0; + int code; + int i; + const char* exts[] = { + "SIZE", + }; + const int maxmask = (1 << (sizeof(exts)/sizeof(char*))) - 1; + + /* Ok, remote host will talk to us. Let's look if we can use ESMTP */ + do_helo("EHLO "); + + code = smtpcode(); + /* remote host does not like our EHLO. Maybe HELO is better? */ + if (code >= 500) { + is_esmtp = 0; + do_helo("HELO "); + code = smtpcode(); + } + if (code != 250) + quit("ZConnected to "," but my name was rejected"); + + if (!is_esmtp) + return 0; + + /* if this is a one line answer there will be no extensions */ + if (smtptext.s[0] == ' ') + return 0; + + /* go through all lines of the multi line answer until we found all + known extensions or we reach the last line */ + do { + /* set search to the index of the next extension in the answer: + it's always 5 characters after the '\n' (the other 4 are + normally "250-") */ + search += 5 + str_chr(smtptext.s + search, '\n'); + + for (i = (sizeof(exts)/sizeof(char*)) - 1; i >= 0; i--) + if (!case_diffb(smtptext.s + search, str_len(exts[i]), exts[i])) { + extensions |= (1<\r\n"); + if (extensions & 1) { + substdio_put(&smtpto, "> SIZE=", 7); + substdio_puts(&smtpto, msgsize); + substdio_put(&smtpto, "\r\n", 2); + } else { + substdio_put(&smtpto, ">\r\n", 3); + } substdio_flush(&smtpto); code = smtpcode(); if (code >= 500) quit("DConnected to "," but sender was rejected"); @@ -240,9 +315,9 @@ void smtp() flagbother = 0; for (i = 0;i < reciplist.len;++i) { - substdio_puts(&smtpto,"RCPT TO:<"); + substdio_put(&smtpto,"RCPT TO:<", 9); substdio_put(&smtpto,reciplist.sa[i].s,reciplist.sa[i].len); - substdio_puts(&smtpto,">\r\n"); + substdio_put(&smtpto,">\r\n", 3); substdio_flush(&smtpto); code = smtpcode(); if (code >= 500) { @@ -340,7 +415,7 @@ char **argv; char *relayhost; sig_pipeignore(); - if (argc < 4) perm_usage(); + if (argc < 5) perm_usage(); if (chdir(auto_qmail) == -1) temp_chdir(); getcontrols(); @@ -370,7 +444,7 @@ char **argv; if (ipme_init() != 1) temp_oserr(); flagallaliases = 1; - recips = argv + 3; + recips = argv + 4; while (*recips) { if (!saa_readyplus(&reciplist,1)) temp_nomem(); reciplist.sa[reciplist.len] = sauninit; @@ -417,7 +490,7 @@ char **argv; if (timeoutconn(smtpfd,&ip.ix[i].ip,(unsigned int) port,timeoutconnect) == 0) { tcpto_err(&ip.ix[i].ip,0); partner = ip.ix[i].ip; - smtp(); /* does not return */ + smtp(argv[3]); /* does not return */ } tcpto_err(&ip.ix[i].ip,errno == error_timeout); close(smtpfd); diff -aup orig/qmail-rspawn.c size/qmail-rspawn.c --- orig/qmail-rspawn.c 1998-06-15 12:53:16.000000000 +0200 +++ size/qmail-rspawn.c 2004-05-21 00:50:27.426157400 +0200 @@ -5,6 +5,7 @@ #include "fork.h" #include "error.h" #include "tcpto.h" +#include "fmt.h" void initialize(argc,argv) int argc; @@ -77,18 +78,20 @@ int len; } } -int spawn(fdmess,fdout,s,r,at) -int fdmess; int fdout; -char *s; char *r; int at; +int +spawn(int fdmess, int fdout, const unsigned long msgsize, char *s, char *r, const unsigned int at) { int f; - char *(args[5]); + char *(args[6]); + char size_buf[FMT_ULONG]; + size_buf[fmt_ulong(size_buf, msgsize)] = 0; args[0] = "qmail-remote"; args[1] = r + at + 1; args[2] = s; - args[3] = r; - args[4] = 0; + args[3] = size_buf; + args[4] = r; + args[5] = 0; if (!(f = vfork())) { diff -aup orig/spawn.c size/spawn.c --- orig/spawn.c 1998-06-15 12:53:16.000000000 +0200 +++ size/spawn.c 2004-05-21 00:47:56.340125968 +0200 @@ -80,7 +80,7 @@ void docmd() { int f; int i; - int j; + unsigned int j; int fdmess; int pi[2]; struct stat st; @@ -119,7 +119,7 @@ void docmd() coe(pi[0]); - f = spawn(fdmess,pi[1],sender.s,recip.s,j); + f = spawn(fdmess,pi[1],st.st_size,sender.s,recip.s,j); close(fdmess); if (f == -1) { close(pi[0]); close(pi[1]); err("Zqmail-spawn unable to fork. (#4.3.0)\n"); return; }