rohrpost

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

ids.c (1149B)


      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 #include <time.h>
     10 #include <strings.h>
     11 #include <sys/types.h>
     12 #include <sys/wait.h>
     13 #include <signal.h>
     14 #include <string.h>
     15 
     16 #include "ind.h"
     17 #include "arg.h"
     18 #include "cfg.h"
     19 #include "llist.h"
     20 #include "imap.h"
     21 
     22 void
     23 idsusage(char *argv0)
     24 {
     25 	die("usage: %s [-h] [-c cfg] [-m folder] msgs\n", argv0);
     26 }
     27 
     28 int
     29 idsmain(int argc, char *argv[])
     30 {
     31 	config_t *cfg;
     32 	char *selected, *idss, *cfgn, *argv0;
     33 	llist_t *ids;
     34 
     35 	selected = NULL;
     36 	cfgn = NULL;
     37 
     38 	ARGBEGIN(argv0) {
     39 	case 'c':
     40 		cfgn = EARGF(idsusage(argv0));
     41 		break;
     42 	case 'm':
     43 		selected = EARGF(idsusage(argv0));
     44 		break;
     45 	default:
     46 		idsusage(argv0);
     47 	} ARGEND;
     48 
     49 	if (argc < 1)
     50 		idsusage(argv0);
     51 
     52 	cfg = config_init(cfgn);
     53 	if (selected == NULL) {
     54 		selected = config_checkgetstr(cfg, "selected");
     55 	} else {
     56 		selected = memdups(selected);
     57 	}
     58 	config_free(cfg);
     59 
     60 	ids = imap_argv2ids(cfgn, selected, argc, argv);
     61 	if (ids == NULL)
     62 		die("No msgsids selected. Aborting.\n");
     63 
     64 	idss = llist_joinstr(ids, " ");
     65 	llist_free(ids);
     66 	printf("%s\n", idss);
     67 	free(idss);
     68 
     69 	free(selected);
     70 	return 0;
     71 }
     72