module: smtp.c
project: fetchmail
programmer: Harry Hochheiser
+ cleaned up and made rfc821 compliant by Cameron MacPherson
description: Handling of SMTP connections, and processing of mail
to be forwarded via SMTP connections.
int SMTP_helo(int socket,char *host)
{
int ok;
- char buf[SMTPBUFSIZE+1];
- sprintf(buf,"HELO %s",host);
- SockPuts(socket, buf);
+ SockPrintf(socket,"HELO %s\r\n", host);
if (outlevel == O_VERBOSE)
- fprintf(stderr, "SMTP> %s\n", buf);
- ok = SMTP_ok(socket,buf);
+ fprintf(stderr, "SMTP> HELO %s\n", host);
+ ok = SMTP_ok(socket,NULL);
return ok;
}
-
/*********************************************************************
function: SMTP_from
description: Send a "MAIL FROM:" message to the SMTP server.
*********************************************************************/
int SMTP_from(int socket, char *from)
{
- char buf[SMTPBUFSIZE+1]; /* it's as good as size as any... */
int ok;
- SockPrintf(socket, "MAIL FROM: %s\n", from);
- if (outlevel == O_VERBOSE)
- fprintf(stderr, "SMTP> MAIL FROM: %s\n", from);
- ok = SMTP_ok(socket,buf);
+ SockPrintf(socket,"MAIL FROM:<%s>\r\n", from);
+ if (outlevel == O_VERBOSE)
+ fprintf(stderr, "SMTP> MAIL FROM:<%s>\n", from);
+ ok = SMTP_ok(socket,NULL);
return ok;
}
-
/*********************************************************************
function: SMTP_rcpt
description: Send a "RCPT TO:" message to the SMTP server.
*********************************************************************/
int SMTP_rcpt(int socket,char *to)
{
- char buf[SMTPBUFSIZE+1]; /* it's as good as size as any... */
int ok;
- SockPrintf(socket, "RCPT TO: %s\n", to);
+ SockPrintf(socket,"RCPT TO:<%s>\r\n", to);
if (outlevel == O_VERBOSE)
- fprintf(stderr, "SMTP> RCPT TO: %s\n", to);
- ok = SMTP_ok(socket,buf);
-
+ fprintf(stderr, "SMTP> RCPT TO:<%s>\n", to);
+ ok = SMTP_ok(socket,NULL);
return ok;
}
-
/*********************************************************************
function: SMTP_data
description: Send a "DATA" message to the SMTP server.
{
int ok;
- SockPrintf(socket,"DATA\n");
+ SockPrintf(socket,"DATA\r\n");
if (outlevel == O_VERBOSE)
fprintf(stderr, "SMTP> DATA\n");
- ok = SMTP_ok(socket, NULL);
-
+ ok = SMTP_ok(socket,NULL);
+ return ok;
+}
+
+/*********************************************************************
+ function: SMTP_quit
+ description: Send a "QUIT" message to the SMTP server.
+
+ arguments:
+ socket TCP/IP socket for connection to SMTP
+
+ return value: Result of SMTP_OK: based on codes in fetchmail.h.
+
+ *********************************************************************/
+int SMTP_quit(int socket)
+{
+ int ok;
+
+ SockPrintf(socket,"QUIT\r\n");
+ if (outlevel == O_VERBOSE)
+ fprintf(stderr, "SMTP> QUIT\n");
+ ok = SMTP_ok(socket,NULL);
return ok;
}
{
int ok;
- SockPuts(socket,".");
+ SockPrintf(socket,".\r\n");
if (outlevel == O_VERBOSE)
fprintf(stderr, "SMTP> (EOM)\n");
ok = SMTP_ok(socket,NULL);
/*********************************************************************
function: SMTP_rset
- description: Send an "RSET" message to the SMTP server.
+ description: Send a "RSET" message to the SMTP server.
arguments:
socket TCP/IP socket for connection to SMTP
*********************************************************************/
void SMTP_rset(int socket)
{
- SockPrintf(socket,"RSET\n");
+ SockPrintf(socket,"RSET\r\n");
if (outlevel == O_VERBOSE)
fprintf(stderr, "SMTP> RSET\n");
}
int SMTP_ok(int socket,char *argbuf)
{
int ok;
- char buf[SMTPBUFSIZE+1];
/* I can tell that the SMTP server connection is ok if I can read a
status message that starts with "1xx" ,"2xx" or "3xx".
{
return read(socket,buf,sz);
}
-