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

capability.c (1026B)


      1 /*
      2  * Copy me if you can.
      3  * by 20h
      4  */
      5 
      6 #include <unistd.h>
      7 #include <stdio.h>
      8 #include <stdlib.h>
      9 
     10 #include "ind.h"
     11 #include "arg.h"
     12 #include "cfg.h"
     13 #include "llist.h"
     14 #include "imap.h"
     15 #include "capability.h"
     16 
     17 void
     18 capabilityusage(char *argv0)
     19 {
     20 	fprintf(stderr, "usage: %s [-h] [-c cfg]\n", argv0);
     21 	exit(1);
     22 }
     23 
     24 int
     25 capabilitymain(int argc, char *argv[])
     26 {
     27 	config_t *cfg;
     28 	imap_t *imap;
     29 	char *user, *pass, *netspec, *cfgn, *argv0;
     30 	llistelem_t *elem;
     31 
     32 	cfgn = NULL;
     33 
     34 	ARGBEGIN(argv0) {
     35 	case 'c':
     36 		cfgn = EARGF(capabilityusage(argv0));
     37 		break;
     38 	default:
     39 		capabilityusage(argv0);
     40 	} ARGEND;
     41 
     42 	cfg = config_init(cfgn);
     43 	user = (config_checkget(cfg, "imapuser"))->data;
     44 	pass = (config_checkget(cfg, "imappass"))->data;
     45 	netspec = (config_checkget(cfg, "imapnet"))->data;
     46 	imap = imap_new(netspec, user, pass);
     47 	config_free(cfg);
     48 
     49 	if (imap_init(imap))
     50 		imap_die(imap, "imap_init");
     51 
     52 	llist_sort(imap->caps);
     53 	forllist(imap->caps, elem)
     54 		printf("%s\n", elem->key);
     55 
     56 	imap_close(imap);
     57 	imap_free(imap);
     58 	return 0;
     59 }
     60