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"
19 int smtp_response; /* numeric value of SMTP response code */
21 int SMTP_helo(FILE *sockfp,char *host)
22 /* send a "HELO" message to the SMTP listener */
26 fprintf(sockfp,"HELO %s\r\n", host);
27 if (outlevel == O_VERBOSE)
28 error(0, 0, "SMTP> HELO %s", host);
33 int SMTP_from(FILE *sockfp, char *from)
34 /* send a "MAIL FROM:" message to the SMTP listener */
38 fprintf(sockfp,"MAIL FROM:<%s>\r\n", from);
39 if (outlevel == O_VERBOSE)
40 error(0, 0, "SMTP> MAIL FROM:<%s>", from);
45 int SMTP_rcpt(FILE *sockfp, char *to)
46 /* send a "RCPT TO:" message to the SMTP listener */
50 fprintf(sockfp,"RCPT TO:<%s>\r\n", to);
51 if (outlevel == O_VERBOSE)
52 error(0, 0, "SMTP> RCPT TO:<%s>", to);
57 int SMTP_data(FILE *sockfp)
58 /* send a "DATA" message to the SMTP listener */
62 fprintf(sockfp,"DATA\r\n");
63 if (outlevel == O_VERBOSE)
64 error(0, 0, "SMTP> DATA");
69 int SMTP_quit(FILE *sockfp)
70 /* send a "QUIT" message to the SMTP listener */
74 fprintf(sockfp,"QUIT\r\n");
75 if (outlevel == O_VERBOSE)
76 error(0, 0, "SMTP> QUIT");
81 int SMTP_eom(FILE *sockfp)
82 /* send a message data terminator to the SMTP listener */
86 fprintf(sockfp,".\r\n");
87 if (outlevel == O_VERBOSE)
88 error(0, 0, "SMTP>. (EOM)");
93 int SMTP_ok(FILE *sockfp)
94 /* returns status of SMTP connection */
96 char buf[SMTPBUFSIZE], *ip;
98 while ((ip = fgets(buf, sizeof(buf)-1, sockfp)))
102 if (buf[strlen(buf)-1] == '\n')
103 buf[strlen(buf)-1] = '\0';
104 if (buf[strlen(buf)-1] == '\r')
105 buf[strlen(buf)-1] = '\r';
109 if (outlevel == O_VERBOSE)
110 error(0, 0, "SMTP< %s", buf);
111 smtp_response = atoi(buf);
112 if ((buf[0] == '1' || buf[0] == '2' || buf[0] == '3') && buf[3] == ' ')
114 else if (buf[3] != '-')
117 return SM_UNRECOVERABLE;
120 /* smtp.c ends here */