rohrpost

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

meta.c (2034B)


      1 /*
      2  * Copy me if you can.
      3  * by 20h
      4  */
      5 
      6 #include <unistd.h>
      7 #include <stdlib.h>
      8 #include <string.h>
      9 
     10 #include "ind.h"
     11 #include "mime.h"
     12 #include "meta.h"
     13 
     14 #define meta_metadup meta_mimedup
     15 
     16 meta_t *
     17 meta_mimedup(mime_t *mime)
     18 {
     19 	meta_t *meta, *mpart;
     20 	llistelem_t *part;
     21 
     22 	meta = mime_new();
     23 	meta->body = memdup(mime->body, mime->bodylen);
     24 	meta->bodylen = mime->bodylen;
     25 
     26 	meta->partid = memdups(mime->partid);
     27 	meta->ct = memdups(mime->ct);
     28 	meta->cte = memdups(mime->cte);
     29 	meta->charset = memdups(mime->charset);
     30 
     31 	meta->boundary = memdups(mime->boundary);
     32 
     33 	meta->state = mime->state;
     34 
     35 	meta->hdrs = llist_copy(mime->hdrs);
     36 
     37 	if (meta->parts->len > 0) {
     38 		forllist(mime->parts, part) {
     39 			mpart = meta_mimedup((mime_t *)part->data);
     40 			llist_addraw(meta->parts, NULL, mpart, sizeof(mpart));
     41 		}
     42 	}
     43 
     44 	return meta;
     45 }
     46 
     47 llist_t *
     48 meta_headers2mime(mime_t *mime)
     49 {
     50 	llistelem_t *header;
     51 	llist_t *mhdrs;
     52 	char *enc;
     53 
     54 	rhdr = llist_new();
     55 	forllist(meta->hdrs, header) {
     56 		enc = mime_encodeheader(header->data);
     57 		if (enc == NULL)
     58 			continue;
     59 
     60 		llist_add(mhdrs, header->key, enc, strlen(enc)+1);
     61 		free(enc);
     62 	}
     63 
     64 	return mhdrs;
     65 }
     66 
     67 llist_t *
     68 meta_headers2meta(mime_t *mime)
     69 {
     70 	llistelem_t *header;
     71 	llist_t *mhdrs;
     72 	char *enc;
     73 
     74 	rhdr = llist_new();
     75 	forllist(meta->hdrs, header) {
     76 		enc = mime_guessheader(header->data);
     77 		if (enc == NULL)
     78 			continue;
     79 
     80 		llist_add(mhdrs, header->key, enc, strlen(enc)+1);
     81 		free(enc);
     82 	}
     83 
     84 	return mhdrs;
     85 }
     86 
     87 mime_t *
     88 meta2mime(meta_t *meta)
     89 {
     90 	mime_t *mime;
     91 
     92 	mime = NULL;
     93 
     94 	return mime;
     95 }
     96 
     97 meta_t *
     98 mime2meta(mime_t *mime)
     99 {
    100 	llistelem_t *part;
    101 	llist_t *nhdrs;
    102 	mime_t *mpart;
    103 	meta_t *meta;
    104 
    105 	meta = meta_mimedup(mime);
    106 
    107 	forllist(mime->parts, part) {
    108 		mpart = (mime_t *)part->data;
    109 		meta = meta_headers2meta(mpart);
    110 
    111 
    112 	}
    113 
    114 	return meta;
    115 }
    116 
    117 meta_t *
    118 meta_parsebuf(char *str, int len)
    119 {
    120 	meta_t *rmeta;
    121 	mime_t *rmime;
    122 
    123 	rmime = mime_parsebuf(str, len);
    124 	if (rmime == NULL)
    125 		return NULL;
    126 	rmeta = mime2meta(rmime);
    127 	if (rmeta == NULL) {
    128 		mime_free(rmime);
    129 		return NULL;
    130 	}
    131 
    132 	return rmeta;
    133 }
    134