From 7a9b688b7d1d9922ab7894f363d7ba458959e882 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 28 May 2007 04:08:11 +0000 Subject: [PATCH] Minor cleanups to citmail. Added a command-line '-d' parameter to enable debugging to stderr. Fixed an error message or two. Also saved the hostname extracted from the LMTP greeting so we can pass it right back to the LMTP server as part of the LHLO command. --- citadel/citmail.c | 53 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/citadel/citmail.c b/citadel/citmail.c index e5e711378..58c0a61e4 100644 --- a/citadel/citmail.c +++ b/citadel/citmail.c @@ -28,10 +28,8 @@ #endif #include "citadel_dirs.h" -/* #define DEBUG */ /* uncomment to get protocol traces */ - int serv_sock; - +int debug = 0; void strip_trailing_nonprint(char *buf) { @@ -135,9 +133,7 @@ void serv_gets(char *buf) */ buf[i] = 0; strip_trailing_nonprint(buf); -#ifdef DEBUG - printf("> %s\n", buf); -#endif + if (debug) fprintf(stderr, "> %s\n", buf); } @@ -146,24 +142,19 @@ void serv_gets(char *buf) */ void serv_puts(char *buf) { -#ifdef DEBUG - printf("< %s\n", buf); -#endif + if (debug) fprintf(stderr, "< %s\n", buf); serv_write(buf, strlen(buf)); serv_write("\n", 1); } - - void cleanup(int exitcode) { char buf[1024]; - if (exitcode == 1) - printf ("Error while sending mail." - "Check your maildata and make shure " - "citadel is configured properly!"); + if (exitcode != 0) { + fprintf(stderr, "Error while sending mail. Please check your Citadel configuration.\n"); + } serv_puts("QUIT"); serv_gets(buf); exit(exitcode); @@ -184,8 +175,14 @@ int main(int argc, char **argv) { char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; char *sp, *ep; - + char hostname[256]; + for (i=1; ipw_name, - sp + hostname ); while (fgets(buf, 1024, stdin) != NULL) { if ( ( (buf[0] == 13) || (buf[0] == 10)) && (in_body == 0) ) { @@ -225,8 +223,8 @@ int main(int argc, char **argv) { } strip_trailing_nonprint(fromline); - - serv_puts("LHLO x"); + sprintf(buf, "LHLO %s", hostname); + serv_puts(buf); do { serv_gets(buf); strcat(buf, " "); @@ -236,14 +234,14 @@ int main(int argc, char **argv) { snprintf(buf, sizeof buf, "MAIL %s", fromline); serv_puts(buf); serv_gets(buf); - if (buf[0]!='2') cleanup(1); + if (buf[0] != '2') cleanup(1); for (i=1; i