tttm

git clone https://orangeshoelaces.net/git/tttm.git

217d94908fc92cc3555daaa94f90a1d04074d218

Author: Vasily Kolobkov on 05/26/2016

Committer: Vasily Kolobkov on 05/26/2016

Ditch quoted message decoding

Only literal strings are fit for 822 messages. Besides, removing cruft
just feels so good! You should try it too ;)

Stats

imap.c | 71 +-------
1 file changed, 4 insertions(+), 67 deletions(-)

Patch

diff --git a/imap.c b/imap.c
index 958a6bf..7d2998e 100644
--- a/imap.c
+++ b/imap.c
@@ -2,10 +2,8 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
-#include <string.h>
 #include <strings.h>
 #include <unistd.h>
-#include <sys/mman.h>
 
 #include "errors.h"
 #include "laxsrc.h"
@@ -60,7 +58,6 @@ static int dig_exists(struct imapctx *, int, void *);
 static int dig_expunge(struct imapctx *, int, void *);
 static int dig_fetch(struct imapctx *, int, void *);
 
-static int deqmsg(int, struct msgd *);
 static int state2res(union parnode *);
 static int str2cap(struct capmap *, char *, size_t);
 static int isprod(union parnode *, int);
@@ -424,8 +421,8 @@ dig_fetch(struct imapctx *con, int buf, void *ctx)
 		    nstr->str.len) == -1)
 			goto eio;
 	}
-	if (nstr->type == PN_QSTR)
-		e = deqmsg(args->stor, m);
+	if (nstr->type != PN_LSTR)
+		goto eproto;
  exit:
 	return e;
  eio:
@@ -434,68 +431,8 @@ dig_fetch(struct imapctx *con, int buf, void *ctx)
  enil:
 	e = TE_NIL;
 	goto exit;
-}
-
-int
-deqmsg(int stor, struct msgd *m)
-{
-	int e, quot;
-	char *rwnd, *r, *rend;
-	char *wwnd, *w, *wend;
-	size_t rlen, wlen, page;
-	size_t roff, woff;
-	size_t mend;
-	long svar;
-
-	e = quot = 0;
-	mend = m->off + m->len;
-	wwnd = 0;
-
-	if ((svar = sysconf(_SC_PAGE_SIZE)) == -1)
-		goto eio;
-	page = SIZE_MAX & svar;
-
-	for (roff = woff = m->off; roff < mend;) {
-		rlen = MIN(page, mend - roff);
-		rwnd = mmap(0, rlen, PROT_READ, MAP_PRIVATE, stor, roff);
-		if (rwnd == MAP_FAILED)
-			goto eio;
-		rend = rwnd + rlen;
-		for (r = rwnd; r < rend; r++) {
-			if (wwnd && w == wend) {
-				if (munmap(wwnd, wlen) == -1)
-					goto eio;
-				woff += wlen;
-				wwnd = 0;
-			}
-			if (!wwnd) {
-				wlen = MIN(page, mend - woff);
-				wwnd = mmap(0, wlen, PROT_WRITE, MAP_SHARED,
-				    stor, woff);
-				if (wwnd == MAP_FAILED)
-					goto eio;
-				wend = wwnd + wlen;
-				w = wwnd;
-			}
-			if (*r == '\\') {
-				quot = !quot;
-				if (quot)
-					continue;
-			}
-			*w++ = *r;
-			quot = 0;
-		}
-		if (munmap(rwnd, rlen) == -1)
-			goto eio;
-		roff += rlen;
-	}
-	if (wwnd && munmap(wwnd, wlen) == -1)
-		goto eio;
-	m->len = (woff - m->off) + (w - wwnd);
- exit:
-	return e;
- eio:
-	e = TE_CACHEIO;
+ eproto:
+	e = TE_PROTO;
 	goto exit;
 }