rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | LICENSE

commit a5ac62e0573501ff40cfc0baa638415a97a0a429
parent 44508eab27f021534ff93563033eb4470d679ada
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 28 Jan 2012 08:01:26 +0100

Meta and spam checking in header decoding.

Diffstat:
bin/rpscanup | 2+-
bin/rpviewup | 2+-
meta.c | 78+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
mime.c | 11++++++++---
4 files changed, 79 insertions(+), 14 deletions(-)

diff --git a/bin/rpscanup b/bin/rpscanup @@ -1,4 +1,4 @@ #!/bin/sh -rpuscan "$@" | eval $PAGER +rpscanu "$@" | eval $PAGER diff --git a/bin/rpviewup b/bin/rpviewup @@ -1,4 +1,4 @@ #!/bin/sh -rpuview "$@" | eval $PAGER +rpviewu "$@" | eval $PAGER diff --git a/meta.c b/meta.c @@ -7,14 +7,37 @@ #include "mime.h" #include "meta.h" -mime_t * -meta2mime(meta_t *meta) -{ -} +#define meta_metadup meta_mimedup meta_t * -mime2meta(mime_t *mime) +meta_mimedup(mime_t *mime) { + meta_t *meta, *mpart; + llistelem_t *part; + + meta = mime_new(); + meta->body = memdup(mime->body, mime->bodylen); + meta->bodylen = mime->bodylen; + + meta->partid = memdup(mime->partid, strlen(mime->partid)+1); + meta->ct = memdup(mime->ct, strlen(mime->ct)+1); + meta->cte = memdup(mime->cte, strlen(mime->cte)+1); + meta->charset = memdup(mime->charset, strlen(mime->charset)+1); + + meta->boundary = memdup(mime->boundary, strlen(mime->boundary)+1); + + meta->state = mime->state; + + meta->hdrs = llist_copy(mime->hdrs); + + if (meta->parts->len > 0) { + forllist(mime->parts, part) { + mpart = meta_mimedup((mime_t *)part->value); + llist_addraw(meta->parts, NULL, mpart, sizeof(mpart)); + } + } + + return meta; } meta_t * @@ -22,8 +45,11 @@ meta_headers2mime(meta_t *meta) { llistelem_t *header; char *enc; + mime_t *mime; + + mime = meta_metadup(meta); - forllist(meta->hdrs, header) { + forllist(mime->hdrs, header) { enc = mime_encodeheader(header->key, header->value); free(header->value); @@ -31,14 +57,48 @@ meta_headers2mime(meta_t *meta) header->datalen = strlen(enc); } + return mime; +} + +meta_t * +meta_headers2meta(mime_t *mime) +{ + llistelem_t *header; + char *enc; + meta_t *meta; + + meta = meta_mimedup(mime); + + forllist(meta->headers, header) { + enc = mime_decodeheader(header->value); + + free(header->value); + header->value = enc; + header->datalen = strlen(enc); + } + return meta; } +mime_t * +meta2mime(meta_t *meta) +{ +} + meta_t * -meta_headers2meta(meta_t *meta) +mime2meta(mime_t *mime) { - llistelem_t *param; - llist_t *headers; + llistelem_t *part; + mime_t *mpart; + meta_t *meta; + + meta = meta_mimedup(mime); + + forllist(mime->parts, part) { + mpart = (mime_t *)part->value; + + + } } meta_t * diff --git a/mime.c b/mime.c @@ -230,7 +230,7 @@ char * mime_decodeheader(char *value) { char *work, *extp, *extw, *extb, *exte, *extr, *ret, *q1, *q2; - int vlen, rlen, elen, wasenc; + int vlen, rlen, elen, wasenc, i; ret = NULL; rlen = 0; @@ -239,7 +239,10 @@ mime_decodeheader(char *value) extp = work; wasenc = 0; - for (;;) { + /* + * Avoid being tricked by malformed headers. + */ + for (i = 0; i < 32; i++) { extb = strstr(extp, "=?"); if (extb != NULL) { elen = extb - extp; @@ -334,7 +337,9 @@ char * mime_encodeheader(char *header, char *value) { char *ret, *b64, *p, *mp, *str; - int len, hlen, lmax, isascii = 0, firstline, slen; + int len, hlen, lmax, isascii, firstline, slen; + + isascii = 0; /* * RFC 2047: