commit be8564b16990a8c9c36c7519c5372860d083e996
parent 03b1147df0e9a5c124a30c9361ef01abcae32921
Author: pancake@localhost.localdomain <unknown>
Date: Sun, 1 Nov 2009 23:39:40 +0100
* Initial implementation of dmc-mbox
* Fix make uninstall and add dmc-mbox build
* Fix config.def.mk issue
Diffstat:
5 files changed, 87 insertions(+), 16 deletions(-)
diff --git a/Makefile b/Makefile
@@ -7,7 +7,9 @@ endif
CFLAGS+=-DHAVE_SSL=${HAVE_SSL}
CFLAGS+=-DVERSION=\"${VERSION}\"
-all: config.mk dmc-smtp dmc-pop3 dmc-imap4 dmc-pack
+BINS=dmc-mbox dmc-smtp dmc-pop3 dmc-imap4 dmc-pack dmc-mbox
+
+all: config.mk ${BINS}
config.mk:
@echo creating $@ from config.def.mk
@@ -17,7 +19,9 @@ config.mk:
dmc-smtp: smtp.o
${CC} ${LDFLAGS} smtp.o -o dmc-smtp -lresolv
-# sock.c ?
+dmc-mbox: mbox.o
+ ${CC} ${LDFLAGS} ${SSL_LIBS} mbox.o -o dmc-mbox
+
dmc-pop3: pop3.o
${CC} ${LDFLAGS} ${SSL_LIBS} pop3.o -o dmc-pop3
@@ -28,7 +32,7 @@ dmc-pack: pack.o
${CC} ${LDFLAGS} pack.o -o dmc-pack
install:
- chmod +x dmc dmc-tag
+ chmod +x dmc dmc-tag dmc-mdir
cp -f dmc.1 ${PREFIX}/share/man/man1
cp -f dmc ${PREFIX}/bin
cp -f dmc-tag ${PREFIX}/bin
@@ -36,16 +40,16 @@ install:
cp -f dmc-pop3 ${PREFIX}/bin
cp -f dmc-imap4 ${PREFIX}/bin
cp -f dmc-pack ${PREFIX}/bin
+ cp -f dmc-mbox ${PREFIX}/bin
+ cp -f dmc-mdir ${PREFIX}/bin
uninstall:
rm -f ${PREFIX}/bin/dmc
- rm -f ${PREFIX}/bin/dmc-smtp
- rm -f ${PREFIX}/bin/dmc-pop3
- rm -f ${PREFIX}/bin/dmc-imap4
- rm -f ${PREFIX}/bin/dmc-pack
+ rm -f ${PREFIX}/bin/dmc-*
+ rm -f ${PREFIX}/share/man/man1/dmc.1
clean:
- rm -f dmc-pop3 dmc-imap4 dmc-smtp dmc-pack *.o
+ rm -f ${BINS} *.o
dist:
mkdir -p dmc-${VERSION}
diff --git a/config.def.mk b/config.def.mk
@@ -0,0 +1,7 @@
+VERSION = 0.1
+
+PREFIX ?= /usr
+CFLAGS ?= -Wall
+HAVE_SSL = 1
+
+CC ?= gcc
diff --git a/config.mk b/config.mk
@@ -1,7 +0,0 @@
-VERSION = 0.1
-
-PREFIX ?= /usr
-CFLAGS ?= -Wall
-HAVE_SSL = 1
-
-CC ?= gcc
diff --git a/mbox.c b/mbox.c
@@ -0,0 +1,67 @@
+/* dmc :: Copyleft 2009 -- pancake (at) nopcode (dot) org */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+FILE *fd;
+static char word[1024];
+
+static void mbox_ls () {
+ // TODO
+ // printf("%d %d\n", i, size);
+}
+
+static void mbox_cat (int idx, int body) {
+ // TODO
+}
+
+static void mbox_rm (int idx) {
+ // TODO
+}
+
+static char *getword () {
+ fscanf (stdin, "%255s", word);
+ if (feof (stdin))
+ *word = '\0';
+ return word;
+}
+
+static int doword (char *word) {
+ int ret = 1;
+ if (*word == '\0') {
+ /* Do nothing */
+ } else
+ if (!strcmp (word, "ls")) {
+ mbox_ls ();
+ } else
+ if (!strcmp (word, "cat")) {
+ mbox_cat (atoi (getword ()), 1);
+ } else
+ if (!strcmp (word, "rm")) {
+ mbox_rm (atoi (getword ()));
+ } else
+ if (!strcmp (word, "head")) {
+ mbox_cat (atoi (getword ()), 0);
+ } else
+ if (!strcmp (word, "login")) {
+ getword (); // ignore login
+ getword (); // ignore password
+ } else
+ if (!strcmp (word, "exit"))
+ ret = 0;
+ return ret;
+}
+
+int main (int argc, char **argv) {
+ int ret = 1;
+ if (argc>1) {
+ fd = fopen (argv[1], "r");
+ if (fd != NULL) {
+ ret = 0;
+ while (doword (getword ()));
+ fclose (fd);
+ } else fprintf (stderr, "Cannot open %s\n", argv[1]);
+ } else fprintf (stderr, "Usage: dmc-mbox [mbox-file] 2> body > fifo < input\n");
+ return ret;
+}
diff --git a/pop3.c b/pop3.c
@@ -108,7 +108,7 @@ int main(int argc, char **argv) {
ret = 0;
atexit (sock_close);
waitreply ();
- while (doword (getword()));
+ while (doword (getword ()));
} else fprintf (stderr, "Cannot connect to %s %d\n", argv[1], atoi(argv[2]));
} else fprintf (stderr, "Usage: dmc-pop3 host port [ssl] 2> body > fifo < input\n");
return 0;