commit 47cc67322d823adaf4cd2089253ef3d5c0afbb6a
parent be8564b16990a8c9c36c7519c5372860d083e996
Author: pancake@localhost.localdomain <unknown>
Date: Sun, 1 Nov 2009 23:53:11 +0100
* s/\t/ /g on imap4.c and smtp.c
Diffstat:
imap4.c | | | 290 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
smtp.c | | | 136 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
2 files changed, 213 insertions(+), 213 deletions(-)
diff --git a/imap4.c b/imap4.c
@@ -20,71 +20,71 @@ static char *dir;
/* XXX full of bugs and ugly code */
static char *getword() {
- char *p = NULL;
- char *str = word;
- *word=0;
+ char *p = NULL;
+ char *str = word;
+ *word=0;
reread:
- fscanf(stdin, "%255s", str);
- if (feof(stdin))
- *str = '\0';
- else {
- if (str == word) {
- if (*word=='"') {
- strcpy(word, word+1);
- p = strchr(word, '"');
- if (!p) {
- str = word+strlen(word);
- *str = ' ';
- str++;
- *str = 0;
- goto reread;
- } else *p=0;
- }
- } else {
- p = strchr(str, '"');
- if (!p) {
- *str = ' ';
- str++;
- *str = 0;
- goto reread;
- } else *p = 0;
- }
- }
- return word;
+ fscanf(stdin, "%255s", str);
+ if (feof(stdin))
+ *str = '\0';
+ else {
+ if (str == word) {
+ if (*word=='"') {
+ strcpy(word, word+1);
+ p = strchr(word, '"');
+ if (!p) {
+ str = word+strlen(word);
+ *str = ' ';
+ str++;
+ *str = 0;
+ goto reread;
+ } else *p=0;
+ }
+ } else {
+ p = strchr(str, '"');
+ if (!p) {
+ *str = ' ';
+ str++;
+ *str = 0;
+ goto reread;
+ } else *p = 0;
+ }
+ }
+ return word;
}
static int waitreply() {
- char *ptr;
- int lock = 1;
- int line = 0;
- int reply = -1;
- char result[256];
+ char *ptr;
+ int lock = 1;
+ int line = 0;
+ int reply = -1;
+ char result[256];
- ftruncate (2, 0);
- word[0] = result[0] = '\0';
- while(lock || sock_ready()) {
- lock = 0;
- if (sock_read (word, 2024) <1)
- break;
- if (line++ == 0) {
- ptr = strchr(word, ' ');
- if (ptr) {
- if (!memcmp(ptr+1, "OK", 2))
- reply = 1;
- else
- if (!memcmp(ptr+1, "NO", 2))
- reply = 0;
- else // TODO: Do 'BAD' should be -1 ?
- if (!memcmp(ptr+1, "BAD", 3))
- reply = 0;
- }
- snprintf (result, 254, "### %s %d \"%s\"\n", cmd, reply, word);
- }
- write (2, word, strlen (word));
- }
-
- write (1, result, strlen(result));
- return reply;
+ ftruncate (2, 0);
+ word[0] = result[0] = '\0';
+ while(lock || sock_ready()) {
+ lock = 0;
+ if (sock_read (word, 2024) <1)
+ break;
+ if (line++ == 0) {
+ ptr = strchr(word, ' ');
+ if (ptr) {
+ if (!memcmp(ptr+1, "OK", 2))
+ reply = 1;
+ else
+ if (!memcmp(ptr+1, "NO", 2))
+ reply = 0;
+ else // TODO: Do 'BAD' should be -1 ?
+ if (!memcmp(ptr+1, "BAD", 3))
+ reply = 0;
+ }
+ snprintf (result, 254, "### %s %d \"%s\"\n", cmd, reply, word);
+ }
+ write (2, word, strlen (word));
+ }
+
+ write (1, result, strlen(result));
+ return reply;
}
#if 0
@@ -97,92 +97,92 @@ EXPUNGE - permanent remove of deltec
RECENT - show the number of recent messages
#endif
static int doword (char *word) {
- int ret = 1;
- free (cmd);
- cmd = strdup(word);
- if (*word == '\0') {
- /* Do nothing */
- } else
- if (!strcmp(word, "exit")) {
- sock_printf("%d LOGOUT\n", ctr++);
- waitreply();
- ret = 0;
- } else
- if (!strcmp(word, "help") || !strcmp(word, "?")) {
- fprintf(stderr, "Use: login exit find cd pwd ls cat head rm rmdir mkdir mvdir\n");
- } else
- if (!strcmp(word, "pwd")) {
- fprintf(stderr, "%s\n", dir);
- } else
- if (!strcmp(word, "cd")) {
- free(dir);
- dir = strdup(getword());
- if (!strcmp(dir, "\"\""))
- *dir=0;
- sock_printf ("%d SELECT \"%s\"\n", ctr++, dir);
- waitreply();
- } else
- if (!strcmp(word, "find")) {
- sock_printf ("%d SEARCH TEXT \"%s\"\n", ctr++, getword());
- waitreply();
- } else
- if (!strcmp(word, "ls")) {
- sock_printf ("%d LIST \"%s\" *\n", ctr++, dir);
- waitreply();
- } else
- if (!strcmp(word, "cat")) {
- sock_printf ("%d FETCH %d body[]\n",
- ctr++, atoi(getword()));
- waitreply();
- } else
- if (!strcmp(word, "head")) {
- sock_printf ("%d FETCH %d body[header]\n",
- ctr++, atoi(getword()));
- waitreply();
- } else
- if (!strcmp(word, "mvdir")) {
- sock_printf ("%d RENAME %s %s\n",
- ctr++, getword(), getword());
- } else
- if (!strcmp(word, "mkdir")) {
- sock_printf ("%d CREATE \"%s\"\n", ctr++, getword());
- } else
- if (!strcmp(word, "rm")) {
- sock_printf ("%d DELE %d\n", ctr++, atoi(getword()));
- waitreply ();
- } else
- if (!strcmp(word, "rmdir")) {
- printf("%d DELETE \"%s\"\n",
- ctr++, getword());
- waitreply();
- } else
- if (!strcmp(word, "login")) {
- char *user = strdup (getword ());
- char *pass = strdup (getword ());
- sock_printf ("%d LOGIN \"%s\" \"%s\"\n",
- ctr++, user, pass);
- free (user);
- free (pass);
- waitreply();
- } else {
- sock_printf ("%d NOOP\n", ctr++);
- waitreply();
- }
- return ret;
+ int ret = 1;
+ free (cmd);
+ cmd = strdup(word);
+ if (*word == '\0') {
+ /* Do nothing */
+ } else
+ if (!strcmp(word, "exit")) {
+ sock_printf("%d LOGOUT\n", ctr++);
+ waitreply();
+ ret = 0;
+ } else
+ if (!strcmp(word, "help") || !strcmp(word, "?")) {
+ fprintf(stderr, "Use: login exit find cd pwd ls cat head rm rmdir mkdir mvdir\n");
+ } else
+ if (!strcmp(word, "pwd")) {
+ fprintf(stderr, "%s\n", dir);
+ } else
+ if (!strcmp(word, "cd")) {
+ free(dir);
+ dir = strdup(getword());
+ if (!strcmp(dir, "\"\""))
+ *dir=0;
+ sock_printf ("%d SELECT \"%s\"\n", ctr++, dir);
+ waitreply();
+ } else
+ if (!strcmp(word, "find")) {
+ sock_printf ("%d SEARCH TEXT \"%s\"\n", ctr++, getword());
+ waitreply();
+ } else
+ if (!strcmp(word, "ls")) {
+ sock_printf ("%d LIST \"%s\" *\n", ctr++, dir);
+ waitreply();
+ } else
+ if (!strcmp(word, "cat")) {
+ sock_printf ("%d FETCH %d body[]\n",
+ ctr++, atoi(getword()));
+ waitreply();
+ } else
+ if (!strcmp(word, "head")) {
+ sock_printf ("%d FETCH %d body[header]\n",
+ ctr++, atoi(getword()));
+ waitreply();
+ } else
+ if (!strcmp(word, "mvdir")) {
+ sock_printf ("%d RENAME %s %s\n",
+ ctr++, getword(), getword());
+ } else
+ if (!strcmp(word, "mkdir")) {
+ sock_printf ("%d CREATE \"%s\"\n", ctr++, getword());
+ } else
+ if (!strcmp(word, "rm")) {
+ sock_printf ("%d DELE %d\n", ctr++, atoi(getword()));
+ waitreply ();
+ } else
+ if (!strcmp(word, "rmdir")) {
+ printf("%d DELETE \"%s\"\n",
+ ctr++, getword());
+ waitreply();
+ } else
+ if (!strcmp(word, "login")) {
+ char *user = strdup (getword ());
+ char *pass = strdup (getword ());
+ sock_printf ("%d LOGIN \"%s\" \"%s\"\n",
+ ctr++, user, pass);
+ free (user);
+ free (pass);
+ waitreply();
+ } else {
+ sock_printf ("%d NOOP\n", ctr++);
+ waitreply();
+ }
+ return ret;
}
int main (int argc, char **argv) {
- int ssl = 0, ret = 0;
- if (argc>2) {
- if (argc>3)
- ssl = (*argv[3]=='1');
- if (sock_connect (argv[1], atoi (argv[2]), ssl) >= 0) {
- ret = 0;
- atexit (sock_close);
- waitreply ();
- dir = strdup ("");
- while (doword (getword()));
- } else fprintf (stderr, "Cannot connect to %s %d\n", argv[1], atoi(argv[2]));
- } else fprintf(stderr, "Usage: dmc-imap4 host port 2> body > fifo < input\n");
- return ret;
+ int ssl = 0, ret = 0;
+ if (argc>2) {
+ if (argc>3)
+ ssl = (*argv[3]=='1');
+ if (sock_connect (argv[1], atoi (argv[2]), ssl) >= 0) {
+ ret = 0;
+ atexit (sock_close);
+ waitreply ();
+ dir = strdup ("");
+ while (doword (getword()));
+ } else fprintf (stderr, "Cannot connect to %s %d\n", argv[1], atoi(argv[2]));
+ } else fprintf(stderr, "Usage: dmc-imap4 host port 2> body > fifo < input\n");
+ return ret;
}
diff --git a/smtp.c b/smtp.c
@@ -11,81 +11,81 @@
#define BIND_4_COMPAT
static int resmx(const char *domain) {
- char host[NS_MAXDNAME+1];
- char last[NS_MAXDNAME+1];
- typedef union {
- HEADER head;
- char buf[PACKETSZ];
- } pkt_t;
- unsigned char buf[PACKETSZ];
- unsigned char *rrptr;
- pkt_t *pkt = (pkt_t *)buf;
- int querylen, len, n, exprc;
- int rrtype, antrrtype;
- int rrpayloadsz;
+ char host[NS_MAXDNAME+1];
+ char last[NS_MAXDNAME+1];
+ typedef union {
+ HEADER head;
+ char buf[PACKETSZ];
+ } pkt_t;
+ unsigned char buf[PACKETSZ];
+ unsigned char *rrptr;
+ pkt_t *pkt = (pkt_t *)buf;
+ int querylen, len, n, exprc;
+ int rrtype, antrrtype;
+ int rrpayloadsz;
- querylen = res_querydomain(domain, "", C_IN,T_MX,
- (void*)&buf, PACKETSZ);
+ querylen = res_querydomain(domain, "", C_IN,T_MX,
+ (void*)&buf, PACKETSZ);
- if (ntohs(pkt->head.rcode) == NOERROR) {
- n = ntohs(pkt->head.ancount);
- if (n==0) {
- fprintf(stderr, "No MX found\n");
- return 1;
- }
+ if (ntohs(pkt->head.rcode) == NOERROR) {
+ n = ntohs(pkt->head.ancount);
+ if (n==0) {
+ fprintf(stderr, "No MX found\n");
+ return 1;
+ }
- /* expand DNS query */
- len = dn_expand( buf,
- buf+querylen, buf+sizeof(HEADER),
- host, sizeof(host));
+ /* expand DNS query */
+ len = dn_expand( buf,
+ buf+querylen, buf+sizeof(HEADER),
+ host, sizeof(host));
- if (len<0) {
- fprintf(stderr, "No MX found\n");
- return 1;
- }
+ if (len<0) {
+ fprintf(stderr, "No MX found\n");
+ return 1;
+ }
- rrptr = buf+sizeof(HEADER)+4+len;
+ rrptr = buf+sizeof(HEADER)+4+len;
- while(rrptr < buf+querylen) {
- /* expand NAME resolved */
- exprc = dn_expand(buf,buf+querylen,rrptr,host,sizeof(host));
- if (exprc<0) {
- fprintf(stderr, "No MX found\n");
- return 1;
- }
- rrptr += exprc;
- rrtype = (rrptr[0]<<8|rrptr[1]);
- rrpayloadsz = (rrptr[8]<<8|rrptr[9]);
- rrptr += 10;
- switch(rrtype) {
- /* TODO support for IPv6: case T_AAAA: */
- case T_A:
- if (strcmp(host, last)) {
- printf("%s\n", host);
- if (--n==0) querylen=0;
- }
- break;
- }
- antrrtype = rrtype;
- rrptr += rrpayloadsz;
- }
- } else {
- printf("%s\n", domain);
- //fprintf(stderr, "No MX found\n");
- return 1;
- }
- return 0;
+ while(rrptr < buf+querylen) {
+ /* expand NAME resolved */
+ exprc = dn_expand(buf,buf+querylen,rrptr,host,sizeof(host));
+ if (exprc<0) {
+ fprintf(stderr, "No MX found\n");
+ return 1;
+ }
+ rrptr += exprc;
+ rrtype = (rrptr[0]<<8|rrptr[1]);
+ rrpayloadsz = (rrptr[8]<<8|rrptr[9]);
+ rrptr += 10;
+ switch(rrtype) {
+ /* TODO support for IPv6: case T_AAAA: */
+ case T_A:
+ if (strcmp(host, last)) {
+ printf("%s\n", host);
+ if (--n==0) querylen=0;
+ }
+ break;
+ }
+ antrrtype = rrtype;
+ rrptr += rrpayloadsz;
+ }
+ } else {
+ printf("%s\n", domain);
+ //fprintf(stderr, "No MX found\n");
+ return 1;
+ }
+ return 0;
}
int main(int argc, char **argv) {
- if (argc>1) {
- char *ch = strchr(argv[1], '@');
- if (ch) return resmx(ch+1);
- else {
- /* do the daemon stuff here */
- fprintf(stderr, "TODO: SMTP protocol not yet implemented\n");
- }
- } else printf("Usage: dmc-smtp [user@domain] # Get MX for domain\n"
- "Usage: dmc-smtp fifo | nc host 25 > fifo\n");
- return 0;
+ if (argc>1) {
+ char *ch = strchr(argv[1], '@');
+ if (ch) return resmx(ch+1);
+ else {
+ /* do the daemon stuff here */
+ fprintf(stderr, "TODO: SMTP protocol not yet implemented\n");
+ }
+ } else printf("Usage: dmc-smtp [user@domain] # Get MX for domain\n"
+ "Usage: dmc-smtp fifo | nc host 25 > fifo\n");
+ return 0;
}