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 11edd6f2bdca483d2e1624726d2df5b4532d80ef
parent 980ce8e2a6edf338eadb4cd3d3d26427853b2385
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed, 26 Nov 2014 20:13:46 +0100

Add rp:// URI handling to scan and view.

This adds the memdups() function for string replication too.

Diffstat:
ind.c | 14++++++++++++++
ind.h | 1+
scan.c | 15+++++++++++++--
view.c | 19+++++++++++++++++--
4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/ind.c b/ind.c @@ -85,6 +85,20 @@ memdupz(void *p, int l) return (void *)ret; } +void * +memdups(void *p) +{ + char *ret; + int l; + + l = strlen(p) + 1; + + ret = reallocz(NULL, l, 2); + memmove(ret, p, l); + + return (void *)ret; +} + /* * Append the data at c with the length of lc to * p, at position lp of p. diff --git a/ind.h b/ind.h @@ -20,6 +20,7 @@ void *reallocz(void *p, int l, int z); void *mallocz(int l, int z); void *memdup(void *p, int l); void *memdupz(void *p, int l); +void *memdups(void *p); void *memdupcat(void *p, int lp, void *c, int lc); char *vsmprintf(char *fmt, va_list fmtargs, int size); char *smprintf(char *fmt, ...); diff --git a/scan.c b/scan.c @@ -80,6 +80,11 @@ scanmain(int argc, char *argv[]) selected = memdup(selected, strlen(selected)+1); } } + if (cfg->name != NULL) { + cfgn = memdup(cfg->name, strlen(cfg->name)+1); + } else { + cfgn = memdup(cfgn, strlen(cfgn)+1); + } config_free(cfg); @@ -165,8 +170,6 @@ scanmain(int argc, char *argv[]) datee = llist_ciget(mime->hdrs, "date"); frome = llist_ciget(mime->hdrs, "from"); - id = (char *)ide->data; - if (subjecte != NULL) { subject = mime_guessheader((char *)subjecte->data); } else { @@ -190,8 +193,15 @@ scanmain(int argc, char *argv[]) from = "<empty>"; } + id = smprintf("rp:/%s/%s/%s", + (!strcmp(cfgn, "default")? "" : cfgn), + selected, + (char *)ide->data); + scan_print(id, date, from, subject); + free(id); + if (subjecte != NULL) free(subject); if (datee != NULL) @@ -204,6 +214,7 @@ scanmain(int argc, char *argv[]) llist_efree(msgs); scancleanup: + free(cfgn); if (filec == NULL) { free(selected); imap_close(imap); diff --git a/view.c b/view.c @@ -276,7 +276,7 @@ viewmain(int argc, char *argv[]) imap_t *imap; int status, filelen, printopts, dodebug; char *user, *pass, *netspec, *selected, *mfilter, *parts, *filec, - *headers, *cfgn; + *headers, *cfgn, *id; llist_t *ids, *msgs, *dhdrs, *partl; llistelem_t *elem, *msg, *ide; mime_t *mime; @@ -350,6 +350,11 @@ viewmain(int argc, char *argv[]) selected = memdup(selected, strlen(selected)+1); } } + if (cfg->name != NULL) { + cfgn = memdups(cfg->name); + } else { + cfgn = memdups(cfgn); + } if (headers == NULL) { mfilter = config_checkgetstr(cfg, "view_msgfilter"); @@ -359,6 +364,7 @@ viewmain(int argc, char *argv[]) printopts |= PRINT_HEADER; dhdrs = llist_splitstr(headers, " ,"); } + config_free(cfg); partl = NULL; @@ -424,7 +430,15 @@ viewmain(int argc, char *argv[]) if (dodebug) mime_print(mime); - view_print((char *)ide->data, mime, dhdrs, partl, printopts); + + id = smprintf("rp:/%s/%s/%s", + ((!strcmp(cfgn, "default"))? "" : cfgn), + selected, + (char *)ide->data); + + view_print(id, mime, dhdrs, partl, printopts); + + free(id); mime_free(mime); } if (ids->last != NULL) { @@ -437,6 +451,7 @@ viewmain(int argc, char *argv[]) llist_efree(msgs); viewcleanup: + free(cfgn); llist_free(dhdrs); if (partl != NULL)