}
+
/*
* Input string from socket - implemented in terms of sock_read()
*
return(strlen(buf));
}
+/*
+ * Multiline version of sock_gets() ... this is a convenience function for
+ * client side protocol implementations. It only returns the first line of
+ * a multiline response, discarding the rest.
+ */
+int ml_sock_gets(int sock, char *buf) {
+ char bigbuf[1024];
+ int g;
+
+ g = sock_gets(sock, buf);
+ if (g < 0) return(g);
+ if ( (g < 4) || (buf[3] != '-')) return(g);
+
+ do {
+ g = sock_gets(sock, bigbuf);
+ if (g < 0) return(g);
+ } while ( (g >= 4) && (bigbuf[3] == '-') );
+
+ return(strlen(buf));
+}
+
/*
* sock_puts() - send line to server - implemented in terms of serv_write()
int sock_connect(char *host, char *service, char *protocol);
int sock_read(int sock, char *buf, int bytes);
int sock_write(int sock, char *buf, int nbytes);
+int ml_sock_gets(int sock, char *buf);
int sock_gets(int sock, char *buf);
int sock_puts(int sock, char *buf);
}
/* Process the SMTP greeting from the server */
- if (sock_gets(sock, buf) < 0) {
+ if (ml_sock_gets(sock, buf) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP conversation");
goto bail;
snprintf(buf, sizeof buf, "HELO %s", config.c_fqdn);
lprintf(9, ">%s\n", buf);
sock_puts(sock, buf);
- if (sock_gets(sock, buf) < 0) {
+ if (ml_sock_gets(sock, buf) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP conversation");
goto bail;
snprintf(buf, sizeof buf, "MAIL From: %s", mailfrom);
lprintf(9, ">%s\n", buf);
sock_puts(sock, buf);
- if (sock_gets(sock, buf) < 0) {
+ if (ml_sock_gets(sock, buf) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP conversation");
goto bail;
snprintf(buf, sizeof buf, "RCPT To: %s", addr);
lprintf(9, ">%s\n", buf);
sock_puts(sock, buf);
- if (sock_gets(sock, buf) < 0) {
+ if (ml_sock_gets(sock, buf) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP conversation");
goto bail;
/* RCPT succeeded, now try the DATA command */
lprintf(9, ">DATA\n");
sock_puts(sock, "DATA");
- if (sock_gets(sock, buf) < 0) {
+ if (ml_sock_gets(sock, buf) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP conversation");
goto bail;
}
sock_write(sock, ".\r\n", 3);
- if (sock_gets(sock, buf) < 0) {
+ if (ml_sock_gets(sock, buf) < 0) {
*status = 4;
strcpy(dsn, "Connection broken during SMTP conversation");
goto bail;
lprintf(9, ">QUIT\n");
sock_puts(sock, "QUIT");
- sock_gets(sock, buf);
+ ml_sock_gets(sock, buf);
lprintf(9, "<%s\n", buf);
bail: if (msg_fp != NULL) fclose(msg_fp);