2 * smtp.c -- code for speaking SMTP to a listener port
4 * Concept due to Harry Hochheiser. Implementation by ESR. Cleanup and
5 * strict RFC821 compliance by Cameron MacPherson.
7 * Copyright 1996 Eric S. Raymond
9 * For license terms, see the file COPYING in this directory.
16 #include "fetchmail.h"
20 int smtp_response; /* numeric value of SMTP response code */
22 int SMTP_helo(FILE *sockfp,char *host)
23 /* send a "HELO" message to the SMTP listener */
27 SockPrintf(sockfp,"HELO %s\r\n", host);
28 if (outlevel == O_VERBOSE)
29 error(0, 0, "SMTP> HELO %s", host);
34 int SMTP_from(FILE *sockfp, char *from)
35 /* send a "MAIL FROM:" message to the SMTP listener */
39 SockPrintf(sockfp,"MAIL FROM:<%s>\r\n", from);
40 if (outlevel == O_VERBOSE)
41 error(0, 0, "SMTP> MAIL FROM:<%s>", from);
46 int SMTP_rcpt(FILE *sockfp, char *to)
47 /* send a "RCPT TO:" message to the SMTP listener */
51 SockPrintf(sockfp,"RCPT TO:<%s>\r\n", to);
52 if (outlevel == O_VERBOSE)
53 error(0, 0, "SMTP> RCPT TO:<%s>", to);
58 int SMTP_data(FILE *sockfp)
59 /* send a "DATA" message to the SMTP listener */
63 SockPrintf(sockfp,"DATA\r\n");
64 if (outlevel == O_VERBOSE)
65 error(0, 0, "SMTP> DATA");
70 int SMTP_quit(FILE *sockfp)
71 /* send a "QUIT" message to the SMTP listener */
75 SockPrintf(sockfp,"QUIT\r\n");
76 if (outlevel == O_VERBOSE)
77 error(0, 0, "SMTP> QUIT");
82 int SMTP_eom(FILE *sockfp)
83 /* send a message data terminator to the SMTP listener */
87 SockPrintf(sockfp,".\r\n");
88 if (outlevel == O_VERBOSE)
89 error(0, 0, "SMTP>. (EOM)");
94 int SMTP_ok(FILE *sockfp)
95 /* returns status of SMTP connection */
97 char buf[SMTPBUFSIZE], *ip;
99 while ((ip = SockGets(buf, sizeof(buf)-1, sockfp)))
103 if (buf[strlen(buf)-1] == '\n')
104 buf[strlen(buf)-1] = '\0';
105 if (buf[strlen(buf)-1] == '\r')
106 buf[strlen(buf)-1] = '\r';
110 if (outlevel == O_VERBOSE)
111 error(0, 0, "SMTP< %s", buf);
112 smtp_response = atoi(buf);
113 if ((buf[0] == '1' || buf[0] == '2' || buf[0] == '3') && buf[3] == ' ')
115 else if (buf[3] != '-')
118 return SM_UNRECOVERABLE;
121 /* smtp.c ends here */