36 #include "smtp-strings.h"
37 #include "contiki-net.h"
59 static struct smtp_state s;
61 static char *localhostname;
62 static uip_ipaddr_t smtpserver;
67 #define ISO_period 0x2e
75 #define SEND_STRING(s, str) PSOCK_SEND(s, (uint8_t *)str, (unsigned char)strlen(str))
84 if(strncmp(s.inputbuffer, smtp_220, 3) != 0) {
90 SEND_STRING(&s.psock, (
char *)smtp_helo);
91 SEND_STRING(&s.psock, localhostname);
92 SEND_STRING(&s.psock, (
char *)smtp_crnl);
96 if(s.inputbuffer[0] != ISO_2) {
102 SEND_STRING(&s.psock, (
char *)smtp_mail_from);
103 SEND_STRING(&s.psock, s.from);
104 SEND_STRING(&s.psock, (
char *)smtp_crnl);
108 if(s.inputbuffer[0] != ISO_2) {
114 SEND_STRING(&s.psock, (
char *)smtp_rcpt_to);
115 SEND_STRING(&s.psock, s.to);
116 SEND_STRING(&s.psock, (
char *)smtp_crnl);
120 if(s.inputbuffer[0] != ISO_2) {
127 SEND_STRING(&s.psock, (
char *)smtp_rcpt_to);
128 SEND_STRING(&s.psock, s.cc);
129 SEND_STRING(&s.psock, (
char *)smtp_crnl);
133 if(s.inputbuffer[0] != ISO_2) {
140 SEND_STRING(&s.psock, (
char *)smtp_data);
144 if(s.inputbuffer[0] != ISO_3) {
150 SEND_STRING(&s.psock, (
char *)smtp_to);
151 SEND_STRING(&s.psock, s.to);
152 SEND_STRING(&s.psock, (
char *)smtp_crnl);
155 SEND_STRING(&s.psock, (
char *)smtp_cc);
156 SEND_STRING(&s.psock, s.cc);
157 SEND_STRING(&s.psock, (
char *)smtp_crnl);
160 SEND_STRING(&s.psock, (
char *)smtp_from);
161 SEND_STRING(&s.psock, s.from);
162 SEND_STRING(&s.psock, (
char *)smtp_crnl);
164 SEND_STRING(&s.psock, (
char *)smtp_subject);
165 SEND_STRING(&s.psock, s.subject);
166 SEND_STRING(&s.psock, (
char *)smtp_crnl);
168 for(s.line = 0; s.line < s.msgheight; ++s.line) {
169 SEND_STRING(&s.psock, (
char *)smtp_crnl);
170 SEND_STRING(&s.psock, &s.msg[s.line * s.msgwidth]);
173 SEND_STRING(&s.psock, (
char *)smtp_crnlperiodcrnl);
176 if(s.inputbuffer[0] != ISO_2) {
182 SEND_STRING(&s.psock, (
char *)smtp_quit);
183 smtp_done(SMTP_ERR_OK);
188 smtp_appcall(
void *state)
203 smtp_configure(
char *lhostname, uip_ipaddr_t *server)
205 localhostname = lhostname;
210 smtp_send(
char *to,
char *cc,
char *from,
char *subject,
211 char *msg, uint8_t msgwidth, uint8_t msgheight)
225 s.msgwidth = msgwidth;
226 s.msgheight = msgheight;
228 PSOCK_INIT(&s.psock, (uint8_t *)s.inputbuffer,
sizeof(s.inputbuffer));
#define PSOCK_READTO(psock, c)
Read data up to a specified character.
#define PSOCK_BEGIN(psock)
Start the protosocket protothread in a function.
Representation of a uIP TCP connection.
CCIF struct uip_conn * tcp_connect(uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
Open a TCP connection to the specified IP address and port.
#define uip_aborted()
Has the connection been aborted by the other end?
#define NULL
The null pointer.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
#define PT_THREAD(name_args)
Declaration of a protothread.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
#define PSOCK_INIT(psock, buffer, buffersize)
Initialize a protosocket.
#define PSOCK_CLOSE(psock)
Close a protosocket.
The representation of a protosocket.
#define PSOCK_END(psock)
Declare the end of a protosocket's protothread.
#define PSOCK_EXIT(psock)
Exit the protosocket's protothread.
#define uip_timedout()
Has the connection timed out?
#define uip_closed()
Has the connection been closed by the other end?