diff -uNr postfix-2.6.0.orig/src/smtpd/smtpd.c postfix-2.6.0/src/smtpd/smtpd.c --- postfix-2.6.0.orig/src/smtpd/smtpd.c 2009-04-28 19:49:23.000000000 +0200 +++ postfix-2.6.0/src/smtpd/smtpd.c 2009-05-24 00:17:56.000000000 +0200 @@ -4377,7 +4377,7 @@ } } #endif - smtpd_chat_reply(state, "220 %s", var_smtpd_banner); + smtpd_chat_reply_multiline(state, 220, var_smtpd_banner); } } diff -uNr postfix-2.6.0.orig/src/smtpd/smtpd_chat.c postfix-2.6.0/src/smtpd/smtpd_chat.c --- postfix-2.6.0.orig/src/smtpd/smtpd_chat.c 2009-04-28 19:26:17.000000000 +0200 +++ postfix-2.6.0/src/smtpd/smtpd_chat.c 2009-05-24 00:27:56.000000000 +0200 @@ -14,6 +14,11 @@ /* SMTPD_STATE *state; /* char *format; /* +/* void smtpd_chat_reply_multiline(state, smtp_reply_code, format, ...) +/* SMTPD_STATE *state; +/* int smtp_reply_code; +/* char *format; +/* /* void smtpd_chat_notify(state) /* SMTPD_STATE *state; /* @@ -62,6 +67,7 @@ #include #include /* 44BSD stdarg.h uses abort() */ #include +#include /* Utility library. */ @@ -207,6 +213,61 @@ state->flags |= SMTPD_FLAG_HANGUP; } +/* trim_line - remove trailing whitespace and return a pointer to the first */ +/* non-space char in the string. Based on TRIM() in ../util/dict.c */ +/* WARNING: this function is DESTRUCTIVE. */ + +static char *trim_line( char *line ) { + char *p; + + for (p=line + strlen(line); p > line && ISSPACE(p[-1]); p--); + *p = 0; + + while ( ISSPACE(*line) ) + ++line; + + return ( line ); +} + +/* smtpd_chat_reply_multiline - convert multline string into seperate */ +/* lines, sending each one to smtpd_chat_reply() */ + +#define LINE_SEPARATOR "\n" + +void smtpd_chat_reply_multiline(SMTPD_STATE *state, int smtp_reply_code, char *format,...) +{ + va_list ap; + char *line, *line2; /* one line (of the multiline) reply */ + size_t size; /* size of a single line */ + static VSTRING *temp_line; /* SMTP reply before unescapeing */ + static VSTRING *multiline; /* SMTP reply after unescaping */ + + /* First-time intialization. */ + if (!temp_line) + temp_line = vstring_alloc(512); + if (!multiline) + multiline = vstring_alloc(512); + + va_start(ap, format); + vstring_vsprintf(temp_line, format, ap); + va_end(ap); + + /* unescape lines with "\\n", converting them to "\n" */ + unescape( multiline, STR(temp_line) ); + + line = STR(multiline); + while ( (size = strcspn(line, LINE_SEPARATOR)) < strlen(line) ) { + *(line + size) = 0; + + line2 = trim_line(line); + smtpd_chat_reply(state, "%03d-%s", smtp_reply_code, line2); + + line += size + 1; + } + line2 = trim_line(line); + smtpd_chat_reply(state, "%03d %s", smtp_reply_code, line2); +} + /* print_line - line_wrap callback */ static void print_line(const char *str, int len, int indent, char *context) diff -uNr postfix-2.6.0.orig/src/smtpd/smtpd_chat.h postfix-2.6.0/src/smtpd/smtpd_chat.h --- postfix-2.6.0.orig/src/smtpd/smtpd_chat.h 2006-04-24 20:48:28.000000000 +0200 +++ postfix-2.6.0/src/smtpd/smtpd_chat.h 2009-05-24 00:28:30.000000000 +0200 @@ -15,6 +15,7 @@ extern void smtpd_chat_reset(SMTPD_STATE *); extern void smtpd_chat_query(SMTPD_STATE *); extern void PRINTFLIKE(2, 3) smtpd_chat_reply(SMTPD_STATE *, const char *, ...); +extern void smtpd_chat_reply_multiline(SMTPD_STATE *, int, char *, ...); extern void smtpd_chat_notify(SMTPD_STATE *); /* LICENSE