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 fe8b92be6ec0debe706d3aa4f66a101a45d34161
parent 85fac33ffba9a6b0a6d0704e7283876a7f7576a1
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sat, 13 Oct 2012 22:07:57 +0200

Changing the imap_cmd format.

Diffstat:
imap.c | 55++++++++++++++++++++++++++++---------------------------
imap.h | 2+-
2 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/imap.c b/imap.c @@ -291,22 +291,23 @@ imap_ids2str(llist_t *ids) } void -imap_cmd(imap_t *imap, char *cmd, int argc, ...) +imap_cmd(imap_t *imap, char *cmd, ...) { va_list ap; - char *req, *breq, *tag; - int i; + char *req, *breq, *tag, *arg; - va_start(ap, argc); req = smprintf("%s", cmd); tag = smprintf("a%.3d", ++imap->msgid); - for (i = 0; i < argc; i++) { - breq = smprintf("%s %s", req, va_arg(ap, char *)); + + va_start(ap, cmd); + for (arg = va_arg(ap, char *); arg; arg = va_arg(ap, char *)) { + breq = smprintf("%s %s", req, arg); free(req); req = breq; } va_end(ap); + /* fprintf(stderr, "req: %s %s\n", tag, req); */ net_printf(imap->fd, "%s %s\r\n", tag, req); free(tag); free(req); @@ -315,7 +316,7 @@ imap_cmd(imap_t *imap, char *cmd, int argc, ...) void imap_simplecmd(imap_t *imap, char *cmd) { - imap_cmd(imap, cmd, 0); + imap_cmd(imap, cmd, NULL); } int @@ -690,13 +691,13 @@ imap_append(imap_t *imap, char *mb, llist_t *flags, char *tdate, char *msg) msge = parser_encodestring(msg); if (tdate != NULL && flagstr != NULL) { - imap_cmd(imap, "APPEND", 4, mb, flagstr, tdate, msge); + imap_cmd(imap, "APPEND", mb, flagstr, tdate, msge, NULL); } else if (tdate != NULL && flagstr == NULL) { - imap_cmd(imap, "APPEND", 3, mb, tdate, msge); + imap_cmd(imap, "APPEND", mb, tdate, msge, NULL); } else if (tdate == NULL && flagstr != NULL) { - imap_cmd(imap, "APPEND", 3, mb, flagstr, msge); + imap_cmd(imap, "APPEND", mb, flagstr, msge, NULL); } else { - imap_cmd(imap, "APPEND", 2, mb, msge); + imap_cmd(imap, "APPEND", mb, msge, NULL); } free(msge); @@ -733,7 +734,7 @@ imap_copy(imap_t *imap, llist_t *ids, char *tomb) char *idstr; idstr = imap_ids2str(ids); - imap_cmd(imap, "COPY", 2, idstr, tomb); + imap_cmd(imap, "COPY", idstr, tomb, NULL); free(idstr); return imap_simpleresult(imap); @@ -742,28 +743,28 @@ imap_copy(imap_t *imap, llist_t *ids, char *tomb) int imap_subscribe(imap_t *imap, char *mb) { - imap_cmd(imap, "SUBSCRIBE", 1, mb); - return imap_simpleresult(imap);; + imap_cmd(imap, "SUBSCRIBE", mb, NULL); + return imap_simpleresult(imap); } int imap_unsubscribe(imap_t *imap, char *mb) { - imap_cmd(imap, "UNSUBSCRIBE", 1, mb); + imap_cmd(imap, "UNSUBSCRIBE", mb, NULL); return imap_simpleresult(imap); } int imap_createfolder(imap_t *imap, char *mb) { - imap_cmd(imap, "CREATE", 1, mb); + imap_cmd(imap, "CREATE", mb, NULL); return imap_simpleresult(imap); } int imap_deletefolder(imap_t *imap, char *mb) { - imap_cmd(imap, "DELETE", 1, mb); + imap_cmd(imap, "DELETE", mb, NULL); return imap_simpleresult(imap); } @@ -774,7 +775,7 @@ imap_fetch(imap_t *imap, llist_t *ids, char *req) llist_t *ret; idstr = imap_ids2str(ids); - imap_cmd(imap, "FETCH", 2, idstr, req); + imap_cmd(imap, "FETCH", idstr, req, NULL); free(idstr); ret = NULL; @@ -902,8 +903,8 @@ imap_status(imap_t *imap, char *mb) llistelem_t *elem, *subelem, *lelem; int i; - imap_cmd(imap, "STATUS", 2, mb, "(RECENT MESSAGES UNSEEN UIDNEXT" - " UIDVALIDITY)"); + imap_cmd(imap, "STATUS", mb, "(RECENT MESSAGES UNSEEN UIDNEXT" + " UIDVALIDITY)", NULL); retstru = NULL; if (imap_result(imap, &retstru)) { if (retstru != NULL) @@ -978,7 +979,7 @@ imap_listresponse(imap_t *imap, char *cmd) llist_t *folders, *retstru, *slist; llistelem_t *elem; - imap_cmd(imap, cmd, 2, "\"\"", "*"); + imap_cmd(imap, cmd, "\"\"", "*", NULL); retstru = NULL; if (imap_result(imap, &retstru)) { if (retstru != NULL) @@ -1060,7 +1061,7 @@ imap_statuses(imap_t *imap) int imap_renamefolder(imap_t *imap, char *old, char *new) { - imap_cmd(imap, "RENAME", 2, old, new); + imap_cmd(imap, "RENAME", old, new, NULL); return imap_simpleresult(imap); } @@ -1148,7 +1149,7 @@ imap_searchresult(imap_t *imap) llist_t * imap_search(imap_t *imap, char *pattern) { - imap_cmd(imap, "SEARCH", 3, "CHARSET", "UTF-8", pattern); + imap_cmd(imap, "SEARCH", "CHARSET", "UTF-8", pattern, NULL); return imap_searchresult(imap); } @@ -1159,7 +1160,7 @@ imap_sort(imap_t *imap, char *criteria, char *pattern) char *cstr; cstr = smprintf("(%s)", criteria); - imap_cmd(imap, "SORT", 3, cstr, "UTF-8", pattern); + imap_cmd(imap, "SORT", cstr, "UTF-8", pattern, NULL); free(cstr); return imap_searchresult(imap); @@ -1168,7 +1169,7 @@ imap_sort(imap_t *imap, char *criteria, char *pattern) llist_t * imap_thread(imap_t *imap, char *algorithm, char *pattern) { - imap_cmd(imap, "THREAD", 3, algorithm, "UTF-8", pattern); + imap_cmd(imap, "THREAD", algorithm, "UTF-8", pattern, NULL); return imap_searchresult(imap); } @@ -1178,7 +1179,7 @@ imap_select(imap_t *imap, char *mb) { int rstat; - imap_cmd(imap, "SELECT", 1, mb); + imap_cmd(imap, "SELECT", mb, NULL); rstat = imap_simpleresult(imap); if (!rstat) { @@ -1199,7 +1200,7 @@ imap_store(imap_t *imap, llist_t *ids, char *item, llist_t *flags) flagcon = llist_joinstr(flags, " "); flagstr = smprintf("(%s)", flagcon); free(flagcon); - imap_cmd(imap, "STORE", 3, idstr, item, flagstr); + imap_cmd(imap, "STORE", idstr, item, flagstr, NULL); free(idstr); free(flagstr); diff --git a/imap.h b/imap.h @@ -37,7 +37,7 @@ llist_t *imap_str2ids(char *mailbox, char *str); llist_t *imap_argv2ids(char *mailbox, int argc, char *argv[]); char *imap_ids2str(llist_t *ids); -void imap_cmd(imap_t *imap, char *cmd, int argc, ...); +void imap_cmd(imap_t *imap, char *cmd, ...); void imap_simplecmd(imap_t *imap, char *cmd); int imap_parseline(imap_t *imap, llist_t **ret); int imap_result(imap_t *imap, llist_t **ret);