commit c718f6e6df0f7f9785dc5cab39906cf450b98452
parent e5855f41a42b4f4b7b4aa93508b017a287f5e701
Author: pancake <nopcode.org>
Date: Wed, 5 May 2010 12:01:17 +0200
* Some more doc about pull in TODO
* Minor code cleanup
Diffstat:
TODO | | | 38 | ++++++++++++++++++++++++++++++++++++++ |
dmc.c | | | 1 | - |
imap4.c | | | 11 | ++++++++--- |
mbox.c | | | 58 | +++++++++++++++++++++++++++------------------------------- |
4 files changed, 73 insertions(+), 35 deletions(-)
diff --git a/TODO b/TODO
@@ -1,10 +1,48 @@
TODO
----
+* Make it more fail-fast (use exit, instead of free)
* how to reply a mail?
- dmc -r [mail]
-> runs dmc-filter -b < mail | sed -e 's,^,> ,'
+* how to forward a mail?
+ - dmc -f [mail]
* Create a mail with attachments (dmc -m addr subject file1 file2 file3 ..)
* Attach file to given mail (not last one)
* Define a list of 'subscribed' folders for IMAP
* Pull specific folder (dmc pull [folder])
* getword() is implemented so MANY times.. MERGE!
+
+* pull methods...
+
+ This topic requires some discussion to get a proper design.
+
+ Each fetch backend (imap4, pop3, mdir, ..) needs to implement their own
+ syncronization mechanism. This decision simplifies the work to translate
+ internal messages, open doors for per-protocol optimizations.
+
+ The sync depends on some options:
+
+ - direction: are we going to push local changes to server?
+ or just fetch the new messages?
+ - read/unread messages: we should sync this flag too
+ it is not yet defined in dmc
+ - delete messages from server?
+ - limit number of messages to fetch? (we must remove old messages) dmclimit()?
+
+ Sync algorithm should look like this:
+
+fetchdir ("~/.dmc/box/foo/in/")
+
+fetchdir(dirpath) {
+ dir = opendir (dirpath)
+
+ - fetch last message <---.
+ - check last message in inbox |
+ - repeat until match or limit -'
+
+ foreach (file in dir) {
+ if (isdir (file)) {
+ fetchdir(dir+file);
+ }
+ }
+}
diff --git a/dmc.c b/dmc.c
@@ -21,7 +21,6 @@ static fd_set rfds, wfds;
static void dmcstop();
static int dmcsend(const char *file);
static int fexist(const char *path);
-extern int errno;
static void dmcinit() {
if (!fexist (DMCDIR))
diff --git a/imap4.c b/imap4.c
@@ -13,6 +13,12 @@
#include <sys/types.h>
#include "sock.c"
+#if 0
+cd list.thelist
+ * 3395 EXISTS ->
+ * 0 RECENT -> number of new messages
+#endif
+
#define STRSZ 4095
static char cmd[STRSZ], word[STRSZ];
static char *dir;
@@ -65,8 +71,8 @@ static int waitreply(int catmode) {
word[0] = res[0] = '\0';
while (lock || sock_ready ()) {
lock = 0;
- memset (word, 0, 4096);
- if (sock_read (word, 4095) <1)
+ memset (word, 0, sizeof (word));
+ if (sock_read (word, sizeof (word)-1) <1)
break;
if (line++ == 0) {
ptr = strchr (word, ' ');
@@ -113,7 +119,6 @@ static int waitreply(int catmode) {
}
write (2, word, strlen (word));
}
-
write (1, res, strlen (res));
return reply;
}
diff --git a/mbox.c b/mbox.c
@@ -7,42 +7,44 @@
#include <stdlib.h>
#include <unistd.h>
+#define SZ 1024
+
FILE *fd;
-static char word[1024];
+static char word[SZ];
static void mbox_ls() {
- char b[1024], from[1024], subject[1024], date[1024], *ptr;
+ char b[SZ], from[SZ], subject[SZ], date[SZ], *ptr;
int m = 0, headers = 1;
- b[1023] = '\0';
+ b[SZ-1] = '\0';
fseek (fd, 0, SEEK_SET);
- while (fgets (b, 1023, fd)) {
+ while (fgets (b, SZ-1, fd)) {
if (b[0]=='\n') {
if (headers) {
printf ("%i %s %s %s\n", m++, from, date, subject);
headers = 0;
} else {
- fgets (b, 1023, fd);
+ fgets (b, SZ-1, fd);
if (!memcmp (b, "From ", 5))
headers = 1;
}
}
if (headers) {
if (!memcmp (b, "From: ", 6)) {
- strncpy (from, b+6, 1023);
- from[1023] = '\0';
+ strncpy (from, b+6, SZ-1);
+ from[SZ-1] = '\0';
if ((ptr = strchr (from, '\n')))
ptr[0] = '\0';
} else
if (!memcmp (b, "Subject: ", 9)) {
- strncpy (subject, b+9, 1023);
- subject[1023] = '\0';
+ strncpy (subject, b+9, SZ-1);
+ subject[SZ-1] = '\0';
if ((ptr = strchr (subject, '\n')))
ptr[0] = '\0';
} else
if (!memcmp (b, "Date: ", 6)) {
- strncpy (date, b+6, 1023);
- date[1023] = '\0';
+ strncpy (date, b+6, SZ-1);
+ date[SZ-1] = '\0';
if ((ptr = strchr (date, '\n')))
ptr[0] = '\0';
}
@@ -51,15 +53,15 @@ static void mbox_ls() {
}
static void mbox_cat(int idx, int body) {
- char b[1024];
+ char b[SZ];
int m = 0, headers = 1;
- b[1023] = '\0';
+ b[SZ-1] = '\0';
fseek (fd, 0, SEEK_SET);
- while (fgets (b, 1023, fd)) {
+ while (fgets (b, SZ-1, fd)) {
if (b[0]=='\n') {
if (!headers) {
- fgets (b, 1023, fd);
+ fgets (b, SZ-1, fd);
if (!memcmp (b, "From ", 5)) {
headers = 1;
m++;
@@ -72,19 +74,19 @@ static void mbox_cat(int idx, int body) {
}
static void mbox_rm (int idx) {
- char b[1024], *buf;
+ char b[SZ], *buf;
int m = 0, i = 0, headers = 1, size;
fseek(fd, 0, SEEK_END);
size = ftell (fd);
if (!(buf = malloc (size)))
return;
- b[1023] = '\0';
+ b[SZ-1] = '\0';
fseek (fd, 0, SEEK_SET);
- while (fgets (b, 1023, fd)) {
+ while (fgets (b, SZ-1, fd)) {
if (b[0]=='\n') {
if (!headers) {
- fgets (b, 1023, fd);
+ fgets (b, SZ-1, fd);
if (!memcmp (b, "From ", 5)) {
headers = 1;
if (++m == idx) {
@@ -117,24 +119,18 @@ static int doword (char *word) {
int ret = 1;
if (*word == '\0') {
/* Do nothing */
- } else
- if (!strcmp (word, "ls")) {
+ } else if (!strcmp (word, "ls")) {
mbox_ls ();
- } else
- if (!strcmp (word, "cat")) {
+ } else if (!strcmp (word, "cat")) {
mbox_cat (atoi (getword ()), 1);
- } else
- if (!strcmp (word, "rm")) {
+ } else if (!strcmp (word, "rm")) {
mbox_rm (atoi (getword ()));
- } else
- if (!strcmp (word, "head")) {
+ } else if (!strcmp (word, "head")) {
mbox_cat (atoi (getword ()), 0);
- } else
- if (!strcmp (word, "login")) {
+ } else if (!strcmp (word, "login")) {
getword (); // ignore login
getword (); // ignore password
- } else
- if (!strcmp (word, "exit"))
+ } else if (!strcmp (word, "exit"))
ret = 0;
return ret;
}