dmc

dynamic mail client
git clone git://git.suckless.org/dmc
Log | Files | Refs | README | LICENSE

commit c3b07500a5c3132713e8733b7a11c4c6c980735a
parent 26014c6ffb0b3a3a446e837eaa931534b39e8e1b
Author: pancake@localhost.localdomain <unknown>
Date:   Sun,  1 Nov 2009 21:44:37 +0100

* Code cleanup (-17 LOC)
Diffstat:
dmc | 4++--
imap4.c | 22+++++++---------------
pack.c | 2+-
pop3.c | 17++++-------------
sock.c | 4++--
5 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/dmc b/dmc @@ -23,7 +23,7 @@ function acc_daemon { rm -f "${LOCK}" "${INPUT}" "${OUTPUT}" mkfifo "${LOCK}" "${INPUT}" - echo login ${USER} ${PASS} > ${INPUT} & + (sleep 2 ; echo login ${USER} ${PASS} > ${INPUT} ) & (while : ; do cat ${INPUT} 2> /dev/null ; done) | \ dmc-${PROTOCOL} ${HOST} ${PORT} ${SSL} 2> ${OUTPUT} > ${LOCK} rm -f "${LOCK}" "${INPUT}" "${OUTPUT}" @@ -157,9 +157,9 @@ case "$1" in rm -f ~/.dmc/tmp/$a done sleep 1 - pkill cat rm -f ~/.dmc/tmp/* pkill dmc + pkill cat ;; "push") for a in ~/.dmc/acc/* ; do diff --git a/imap4.c b/imap4.c @@ -53,26 +53,20 @@ reread: return word; } -static void cleanup (void) { - sock_close (); - exit (0); -} - static int waitreply() { - char *ptr, *str = word; + char *ptr; int lock = 1; int line = 0; int reply = -1; char result[256]; ftruncate (2, 0); - *str = 0; - result[0] = '\0'; + word[0] = result[0] = '\0'; while(lock || sock_ready()) { lock = 0; - if (sock_read (str, 2024) <1) + if (sock_read (word, 2024) <1) break; - if (line == 0) { + if (line++ == 0) { ptr = strchr(word, ' '); if (ptr) { if (!memcmp(ptr+1, "OK", 2)) @@ -84,13 +78,11 @@ static int waitreply() { if (!memcmp(ptr+1, "BAD", 3)) reply = 0; } - snprintf (result, 254, "### %s %d \"%s\"\n", cmd, reply, str); + snprintf (result, 254, "### %s %d \"%s\"\n", cmd, reply, word); } - str = str+strlen(str); - line++; + write (2, word, strlen (word)); } - write (2, word, strlen (word)); write (1, result, strlen(result)); return reply; } @@ -186,7 +178,7 @@ int main (int argc, char **argv) { ssl = (*argv[3]=='1'); if (sock_connect (argv[1], atoi (argv[2]), ssl) >= 0) { ret = 0; - atexit (cleanup); + atexit (sock_close); waitreply (); dir = strdup (""); while (doword (getword())); diff --git a/pack.c b/pack.c @@ -5,7 +5,6 @@ #include <string.h> #include <unistd.h> - /* XXX: here? */ static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; @@ -142,6 +141,7 @@ void mime_unpack() } } +/* TODO: Implement dmc-pack -l to only list filenames attached to the mail */ int main(int argc, char **argv) { if(argc < 2 || !strcmp(argv[1], "-h")) diff --git a/pop3.c b/pop3.c @@ -28,7 +28,7 @@ static int waitreply() { int reply = -1; ftruncate (2, 0); - while(lock || sock_ready()) { + while (lock || sock_ready()) { lock = 0; if (sock_read (word, 512) <1) break; @@ -50,13 +50,9 @@ static int waitreply() { ch = strstr (str, "\r\n."); if (ch) *ch = '\0'; - //fprintf(stderr, "%s\n", str); - fputs (str, stderr); + write (2, str, strlen (str)); } - fputs ("", stderr); - fflush (stderr); - fputs (result, stdout); - fflush (stdout); + write (1, result, strlen (result)); /* stderr lseek works on pipes :D */ lseek (2, 0, 0); return reply; @@ -103,11 +99,6 @@ static int doword (char *word) { return ret; } -static void cleanup (void) { - sock_close (); - exit (0); -} - int main(int argc, char **argv) { int ssl = 0, ret = 1; if (argc>2) { @@ -115,7 +106,7 @@ int main(int argc, char **argv) { ssl = (*argv[3]=='1'); if (sock_connect (argv[1], atoi (argv[2]), ssl) >= 0) { ret = 0; - atexit (cleanup); + atexit (sock_close); waitreply (); while (doword (getword())); } else fprintf (stderr, "Cannot connect to %s %d\n", argv[1], atoi(argv[2])); diff --git a/sock.c b/sock.c @@ -69,11 +69,11 @@ static int sock_ready() { return poll((struct pollfd *)&fds, 1, 10); } -int sock_close () { +void sock_close () { #if HAVE_SSL SSL_free (sfd); #endif - return close (fd); + close (fd); } int sock_write (const char *str) {